🔒 Closed diferrence between Method and Function?

Status
Not open for further replies.
In practice they can mean the same thing.

However "method" is more prevalently used in Object Oriented Programming context like Java when talking about object behaviors.

Functions are often used to mean independent methods/behaviors. No object attachment. Functions are often used in non-OOP languages. However there are languages that consider functions as first class objects.

At the end of the day prefer pure functions or objects that follow SRP.
 
In practice they can mean the same thing.

However "method" is more prevalently used in Object Oriented Programming context like Java when talking about object behaviors.

Functions are often used to mean independent methods/behaviors. No object attachment. Functions are often used in non-OOP languages. However there are languages that consider functions as first class objects.

At the end of the day prefer pure functions or objects that follow SRP.
bakit mas prefer ang method sa oop paps? at pwede bang gamitin ang function sa oop? btw paps walang mas clear na explanation sorry paps
 
And method ay usually hindi nagrereturn ng value, nagpa-process lang siya, ang function naman ay nagrereturn ng value.
 
In layman, Method is a function inside a class. tl;dr pag yung function mo ay implemented ng isang class, method ang tawag duun. It doesn't matter kung mag return to ng value or not. Yun lang ang classification para ma determine kung tatawagin ba siyang function or method
eg.

C++:
class Sample
{
public:
    void FunctionB();  
}

void FunctionA()
{
   
}

int main(int argc, char** argv)
{
    Sample sample();
    FunctionA(); // Function
    sample.FunctionB(); // Method (Function parin to pero method na ang tawag dahil sa paraan ng implementation)
   
    return 0;
}
 
Ang totoo ang Method, Function, Subroutine or Procedure ay iisa lang. Code sila na may kanya kanyang silbi. Noong panahon ng C programming language. Tawag sa C ay Procedural Programming Language. Dahil gumagamit siya ng function.

Pero sa mga libro, nagiging depende ang sagot sa programming language o kung gaano ka katagal nagpoprogram
  • sa C/C++/C#/Java/Javascript
    • pareho lang ang ibig sabihin nila dahil lahat ay functions.
  • sa VB
    • Ang Subroutine ay code na hindi nagrereturn ng values
    • Ang Function ay function na nagrereturn ng values
 
Status
Not open for further replies.

About this Thread

  • 6
    Replies
  • 366
    Views
  • 6
    Participants
Last reply from:
programtayo_bspotcom

Trending Topics

Online now

Members online
440
Guests online
6,609
Total visitors
7,049

Forum statistics

Threads
2,281,821
Posts
29,004,138
Members
1,224,622
Latest member
javiergpnzalez
Back
Top