what is a member vs. a property

22,705

Solution 1

A property is one kind of member. Others might be constructors, methods, fields, nested types, conversions, indexers etc - depending on the language/platform, of course. A lot of the time the exact meaning of terminology depends on the context.

To give a C#-specific definition, from the C# 3.0 spec, section 1.6.1:

The following table provides an overview of the kinds of members a class can contain.
(Rows for...)

  • Constants
  • Fields
  • Methods
  • Properties
  • Indexers
  • Events
  • Operators
  • Constructors
  • Destructors
  • Types

Note that that's members of a class. Different "things" have different kinds of members - in C#, an interface can't have a field as a member, for example.

Solution 2

Neither of the two terms has any defined meaning whatsoever in Object-Oriented Programming or Object-Oriented Design. Nor do they have any defined meaning in the overwhelming majority of programming languages.

Only a very small number of programming languages have a concept called property or member, and even fewer have both.

Some examples of languages that have either one of the two are C++ (which has members), ECMAScript (which has properties) and C# (which has both). However, these terms don't necessarily denote the same concepts in different programming languages. For example, the term "member" means roughly the same thing in C++ and C#, but the term "property" means completely different things in ECMAScript and C#. In fact, the term "property" in ECMAScript denotes roughly the same concept (ie. means roughly the same thing) as the term "member" in C++ and C#.

All this is just to say that those two terms mean exactly what the relevant specification for the programming language says they mean, no more and no less. (Insert gratuitous Lewis Carroll quote here.)

Solution 3

Properties is one kind of members.

In C#, for example, a class can have the following members:

  • Constructors
  • Destructors
  • Constants
  • Fields
  • Methods
  • Properties
  • Indexers
  • Operators
  • Events
  • Delegates
  • Classes
  • Interfaces
  • Structs

MSDN: C#: class

Solution 4

Members are just objects or primitive types belonging to a class.

Properties give you more power than members. It's like a simplified way to create getters and setters letting you make, for instance, public getters and private setters; and put whatever logic you want in the way it will be read or written to. They can be used as a way to expose members, being possible to change the reading and writing policy later more easily.

This applies to C#. Not sure if this is true for the other languages though.

Solution 5

Properties are a way to expose fields, where fields are the actual variables. For example (C#):

class Foo {
  private int field;
  public int Property {
    get { return field; }
    set { field = value; }
  }
}
Share:
22,705
eugened
Author by

eugened

My name is Ryan McCauley, and I'm a database/reporting manager for a mid-size cable company. I spent a number of years as a .NET developer (mostly of the VB.NET variety), but now largely focus on T-SQL and the reporting with the Microsoft BI stack. On my own time, I build small apps to help get things done a little better, and have a couple posted at Codeplex: SQL Space Map - if you have some large SQL Server databases and you'd like a visual picture of which tables and indexes are taking up that space, it's the tool for you. SQL Server Contention Monitor - watches as may SQL Servers as you want and alerts you to blocked SPIDs, showing you the block tree (which process is blocking which, an what others are affected). It's still in a pretty alpha-ish phase, but it despite some instability at times, it gets the job done. Check them out and let me know what feedback you have!

Updated on July 10, 2022

Comments

  • eugened
    eugened almost 2 years

    A friend who is new to OO programming asked me the difference between a Member and Property, and I was ashamed to admit that I couldn't give him a good answer. Since properties can also be objects themselves, I was left with a general description and list of exceptions.

    Can somebody please lay out a good definition of when to consider something a member vs. a property? Maybe I'm bastardizing the concept, or is it just that a member is just the internal name I use, and the property is what's exposed to other objects?

    I don't think that not knowing the answer to this question has affected the quality of my programming, and it's just a semantics point, but it still bothers me that I can't explain it to him.