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

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

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

30条回答
  •  时光说笑
    2020-11-21 05:37

    Function is a set of logic that can be used to manipulate data.

    While, Method is function that is used to manipulate the data of the object where it belongs. So technically, if you have a function that is not completely related to your class but was declared in the class, its not a method; It's called a bad design.

提交回复
热议问题