>> private int foo;
>> public int Foo {
>> get { return foo; }
>> set {
>> if (value < 0)
>> ArgumentOutOfRangeException("Value for property Foo must be >=
>> 0");
>> foo = value;
>> }
>> }
>>
>
> private int foo;
>
> public int getFoo() { return foo; }
> public void setFoo( int value) {
> if (value < 0)
> ArgumentOutOfRangeException("Value for property Foo must be >= 0");
> foo = value;
> }
>
> Maybe I've missed the point but.... :-)
Yes, these two are vastly different, as I've expressed earlier you
can't simply identify a property on a Class, take my attached example
a few posts ago and you'll see what I mean.
When you traverse Foo.class.getDeclaredMethods() that match a pattern
of set|get.* and then pair the two up as a property. as also
mentioned, what if getFoo returned a String, while syntactically
correct, this is not type safe.
get/set methods hide the implementation, but they don't enforce the
fact. A property enforces this by exposing the get/set as one.
-Brett
+ Correction, I forgot the "throw" statement on the exception above.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "The
Java Posse" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/javaposse?hl=en
-~----------~----~----~----~------~----~------~--~---