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 definitions for me ? Thanks guys.
These definitions apply as much to procedural-programming as oop ? Thanks.
Function is a combination of instructions coupled together to achieve some result. It may take arguments and return result. If a function doesn’t return a result it is usually called a procedure. Examples:
So functions are to do some particular work. For example, when you need to draw a polygon of 3 lines as a part of a vector image it is more convenient to call
drawLinethrice than to put all the routine for line drawing inline.Methods (“member functions”) are similar to functions, they belongs to classes or objects and usually expresses the verbs of the objects/class. For example, an object of type
Windowusually would have methodsopenandclosewhich do corresponding operations to the object they belong.Properties are as in everyday language and technically are fields of objects/classes with dedicated getter/setter routines (which can be considered as methods. There are languages that don’t have properties and this behavior is achieved using a private field+get/set methods.).