views:

163

answers:

3

Hi, I was trying to find meaning of this terms but especially due to language barrier I was not able to understand what they are used for. I assume that "field" is variable (object too?) in the class while "property" is just an object that returns specific value and cannot contain methods etc. By "member" I understand any object that is declared on the class level. But these are just my assumptions based on commented code samples where some careful programmers used "property region" etc. I would really appreciate if someone could explain it to me.

A: 

The terminology in this area is hopelessly jumbled and varies wildly from language to language, and model to model. Do you have a specific language or platform in mind?

To a first approximation:

  1. SQL discussions often use field and column interchangeably. Field is also the standard terminology for the data members of Java and C# classes.
  2. Member is most commonly used in C++ to refer to member functions, member variables, and so on, for the various different members of a struct/class definition.
Marcelo Cantos
Yes, sorry - c#.
Petr
A: 

Those terms span differetn languages and therefore they overlap quite a bit and the diffrences are more about the concrete languages than about the concept. Property and field areused to describe data in classes, members can be data and behaviour (e.g. methods) in classes. However there are diffrences between properties and fields in C# and Java, but that is syntactic sugar. If you were using prototype based object oriented language (as opposed to the class based) you would talk about slots of objects... If you want to grasp the entire meaning, first choose a language.

Gabriel Ščerbák
+3  A: 

In C# :

fields : These are variables declared at the class level.

public class SomeClass
{
    private int someInteger; // This is a field
    public double someDouble; // This is another field
    protected StringBuidler stringBuidler; // Still another field
}

properties : Often used as accessors to a private field of a class, they can provide get and set methods that wrap some logic around the field manipulation.

public class SomeClass
{
    private StringBuilder stringBuilder;

    // Property declaration
    public StringBuilder StringBuilder
    {
        get 
        { 
            if(this.stringBuilder == null)
                this.stringBuilder = new StringBuidler();

            return this.stringBuilder;
        }
        set
        {
            if(this.stringBuilder == null)
                this.stringbuilder = value;
        }
    }
}

members : Includes fields, properties, methods, events of a class.

Thibault Falise