What's the difference between a method and a function?

前端 未结 30 3266
粉色の甜心
粉色の甜心 2020-11-21 05:08

Can someone provide a simple explanation of methods vs. functions in OOP context?

30条回答
  •  独厮守ぢ
    2020-11-21 05:42

    IMHO people just wanted to invent new word for easier communication between programmers when they wanted to refer to functions inside objects.

    If you are saying methods you mean functions inside the class. If you are saying functions you mean simply functions outside the class.

    The truth is that both words are used to describe functions. Even if you used it wrongly nothing wrong happens. Both words describe well what you want to achieve in your code.

    Function is a code that has to play a role (a function) of doing something. Method is a method to resolve the problem.

    It does the same thing. It is the same thing. If you want to be super precise and go along with the convention you can call methods as the functions inside objects.

提交回复
热议问题