What is Method, Property and Function?

后端 未结 6 1404
失恋的感觉
失恋的感觉 2021-01-02 08:48

Yeah, I\'m struggling with that. I cannot distinguish among them because every explanation I read is so unclear and philosophical enough. Can someone clear up these definiti

6条回答
  •  佛祖请我去吃肉
    2021-01-02 09:33

    Over time, the way people use each of these terms has changed (and will likely keep changing), but here's what they probably mean if you're reading articles written in the last decade or so:

    Functions (aka subroutines) are relatively self-contained, relatively independent pieces of code that make up a larger program.

    Methods are functions attached to specific classes (or instances) in object-oriented programming.

    Properties are an object-oriented idiom. The term describes a one or two functions (depending on the desired program behavior) - a 'getter' that retrieves a value and a 'setter' that sets a value. By convention, properties usually don't have many side-effects. (And the side-effects they do have usually have limited scope: they may validate the item being set, notify listeners of a change, or convert an object's private data to or from a publicly-declared type.)

提交回复
热议问题