2 Apr 2004 09:12
Re: Simple property rules
On 2 Apr 2004, at 03:10, Bill Burdick wrote:
> Maybe the problem with properties is that Groovy automagically defines
> get and set methods. What about just not having Groovy create get/set
> methods and using rules like these for behavior of field syntax:
>
> 1) this.field directly accesses field, not the get/set methods (only
> when using 'this')
Right now using 'field' or 'this.field' will access the field not the
property.
> 2) if there are no get/set methods use the field behaves just like a
> regular Java field
> 3) if there is a get method or a set method, use the standard bean
> introspection rules
I think today the only way to use the getters/setters is to be outside
of the class. i.e. inside the class 'field' refers to the field. If
you're outside the class foo.field uses the getter/setter (i.e. the
field will be invisible so it'll use the getter/setter instead).
> This lets you make a 'backdoor' if you absoultely need to bypass a
> get/set method by creating alternate methods in a class that access
> its fields using 'this.x' instead of 'x' (you could even add these
> methods to someone else's code at runtime if you had to).
Agreed.
Though I confess to really wanting to be able to define simple beans,
easily like this
class Customer {
String name
Integer id
Date dob
Address address
}
without writing reams of getter-setters. Where the above could be
improved is maybe using some syntax sugar to specify specific
getter/setter implementations - like C#'s syntax.
James
-------
http://radio.weblogs.com/0112098/
RSS Feed