Start networking and exchanging professional insights

Register now or log in to join your professional community.

Follow

What are the differences between methods and functions and properties ?

user-image
Question added by Deleted user
Date Posted: 2015/08/09
Mohammad Basheer abu ahmad
by Mohammad Basheer abu ahmad , مشرف كمبيوتر ، الإشراف على الموظفين , قطاع عام

Methods : to apply logic unit

Functions : to determine it

Properties : to choose it

Gayasuddin Mohammed
by Gayasuddin Mohammed , Advocate , Practicing Law before High Court at Hyderabad

In my knowledge, methods and functions are the same and they are the logical units of particular functionality. Properties are the attributes attached to the respective members like private, protect, public, type whether it is a integer, char, double, etc.. Thanks.

Methods and functions are psychologically the same things, that is a unit of business logic. In java the name 'method' is preferred over the name 'function'

Properties on the other hand cannot be compared to methods or functions . The term 'Property' is used more generally for lots of different things and is more frequently used with GUI widgets when writing a desktop GUI software. For most of the developers, 'property' signifies an attribute or quality or characteristic of a particular Object in consideration e.g., ,Read-Only property of a TextField in Java determines whether the TextField is editable or not.

هاشم المشارقة
by هاشم المشارقة , Key Account Manager , Advanced United Systems Ltd. ( A member of Taj Holding Group)

Method is a function which affect an objects.

Function is an just a way to repeat a group of commands by only calling the function name.

Properties is the values related to an object, these values change while the program be executed.

 

Note this example:

the cat is an object and it has a lot of Properties like food, health ... etc.

Also it has a lot of method like eating, sleeping, playing ... etc.

Emad Mohammed said abdalla
by Emad Mohammed said abdalla , ERP & IT Software, operation general manager . , AL DOHA Company

Which one is better to use when it come to return value for example

publicintEmployeeAge{ get{return intEmployeeAge};}

And

 

publicintEmployeeAge(){return intEmployeeAge;}

Properties are a useful way of expressing a feature of an object, allowing get/set in a common way that can be used by APIs like data-binding, reflection and serialization. So for simple values of the object, properties are handy. Properties can't take arguments, should not have significant side-effects*, and should return quickly and repeatably. Also, there is no such thing as an "extension property" (to mirror an extension method) nor a generic property.

(*=lazy loading etc isn't uncommon, however)

Methods (C# doesn't have functions) are better for expressing things that either change the state, or which have an expectation of taking some time and not necessarily being reproducible. They don't tend to work in binding / serialization etc.

Note that properties are actually just a special way of writing methods. There is little functional difference. It is all about expressing intent. The one thing you don't want to expose, however, is fields (the actual intEmployeeAge instance variable).

So I would have:

publicintEmployeeAge{ get{return intEmployeeAge};}

or just (if on the Employee object):

publicintAge{ get{return intEmployeeAge};}  

More Questions Like This

Do you need help in adding the right keywords to your CV? Let our CV writing experts help you.