🔒 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
  • 364
    Views
  • 6
    Participants
Last reply from:
programtayo_bspotcom

Trending Topics

Online now

Members online
1,143
Guests online
1,052
Total visitors
2,195

Forum statistics

Threads
2,271,859
Posts
28,938,649
Members
1,237,885
Latest member
fdaadkfrtz2
Back
Top