Article:
  10 Reasons We Need Java 3.0
Subject:   11 - Add Properties as a language feature
Date:   2002-08-06 06:01:32
From:   powersusa
I wish properties (ala Delphi and I guess C#) were a language feature (and no Java Bean like introspection does not count).


Currently getting and setting encapsulated member variables (ie not a public member) is accomplished with get and set methods:


someVariable = MyObject.getSomePropertyValue;
MyObject.setSomePropertyValue(someVariable);


It is my view that setting and getting encapsulated member variables should be done through the assignment operator.


someVariable = MyObject.someProperty;
MyObject.someProperty = someVariable;


There would still be get and set method for doing the work:


private int fWidth;


// the width property definition
// note: if there is no write path defined
// then the property is read only


width: int read: getWidth write: setWidth;


private int getWidth()
{
return fWidth;
}


private void setWidth(int aWidth)
{
if (aWidth > 0)
fWidth = aWidth;
}