>It breaks the rules of encapsulation and data hiding,

If all you are doing is setting a private field and reading it and it is the
same type (as per the example posted) you are not hiding or encapsulating
anything but instead compromising for the fact the .NET environment will
break binary compatibility if you later switch it to a read/write property.

>It also does not allow any data validation entering the object.

Neither did the example posted hence my reply "If that's all you are
doing..."

Delphi has a rather elegant solution to this;

TMyClass = Class(TObject)
private
  MyPrivate: MyType;
public
  property MyPropertyName: MyType read MyPrivate write MyPrivate default
MyDefaultValue;
end;

This lets you define a property and have it just map to a private field,
later if you wish to add validation and code it changes to;

TMyClass = Class(TObject)
private
  MyPrivate: MyType;
  procedure SetMyPrivate(NewValue: MyType);
public
  property MyPropertyName: MyType read MyPrivate write SetMyPrivate default
MyDefaultValue;
end;

Surprised Mr. Hejlsberg didn't add that to C# being that he architected
both...


[)amien

===================================
This list is hosted by DevelopMentorŪ  http://www.develop.com
NEW! ASP.NET courses you may be interested in:

2 Days of ASP.NET, 29 Sept 2003, in Redmond
http://www.develop.com/courses/2daspdotnet

Guerrilla ASP.NET, 13 Oct 2003, in Boston
http://www.develop.com/courses/gaspdotnet

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to