My current pain point is properties. Am working with Spring and iBATIS
and iBATIS wants to map to Java classes that follow JavaBean
properties convention of getters/setters.
It gets so old and tedious - and clutters up the code readability - to
toss all that getter/setter boilerplate in.
But I really prefer ActionScript3 properties over C#.
I can do data binding to these class properties (just use Bindable
annotation - no need to introduce explicit getter/setter syntax in
order to get databinding capability):
public class RestaurantProduct {
[Bindable]
public var idNo:int;
public var prodName:String;
[Bindable]
public var desc:String;
}
>From some MXML code I'd just use declarative binding, like so:
<mx:Label text="{garlic.idNo}"/>
<mx:Label text="{garlic.desc}"/>
Or make all properties of the class bindable at once:
[Bindable]
public class RestaurantProduct {
public var idNo:int;
public var prodName:String;
public var desc:String;
}
<mx:Label text="{garlic.idNo}"/>
<mx:Label text="{garlic.prodName}"/>
<mx:Label text="{garlic.desc}"/>
But if I want to have explicit getter/setters, then ActionScript3 has
that too:
public class RestaurantProduct {
private var _idNo:int;
// constructor - property idNo can only be set at construction time
public function RestaurantProduct(idno:int) { _idNo = idno; }
[Bindable]
public function get idNo():int { return _idNo; } // getter for
property idNo
[Bindable]
public var prodName:String;
private var _desc:String;
[Bindable]
public function set desc(value:String):void { _desc = value; }
public function get desc():String { return _desc; }
}
The explicit getter/setters are useful when I want to have special
behavior or fine-grained control over bindable events:
public class RestaurantProduct {
[Bindable]
public var idNo:int;
[Bindable]
public var prodName:String;
private var _desc:String;
[Bindable(event="changeDescription")]
public function set description(value:String):void {
if (....) { // do something to see if should really change the
property
_desc = value;
dispatchEvent(new Event("changeDescription"));
}
}
public function get description():String { return _desc; }
}
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---