views:

611

answers:

2

Suppose I use the [RemoteClass] tag to endow a custom Flex class with serialization intelligence.

What happens when I need to change my object (add a new field, remove a field, rename a field, etc)?

Is there a design pattern for handling this in an elegant way?

+1  A: 

Adding or removing generally works.

You'll get runtime warnings in your trace about properties either being missing or not found, but any data that is transferred and has a place to go will still get there. You need to keep this in mind while developing as not all your fields might have valid data.

Changing types, doesn't work so well and will often result in run time exceptions.

I like to use explicit data transfer objects and not to persist my actual data model that's used throughout the app. Then your translation from DTO->Model can take version differences into account.

Marc Hughes
+3  A: 

Your best bet is to do code generation against your backend classes to generation ActionScript counterparts for them. If you generate a base class with all of your object properties and then create a subclass for it which is never modified, you can still add custom code while regenerating only the parts of your class that change. Example:

java:
public class User {
  public Long id;
  public String firstName;
  public String lastName;
}

as3:
public class UserBase {
  public var id : Number;
  public var firstName : String;
  public var lastName : String;
}

[Bindable] [RemoteClass(...)]
public class User extends UserBase {
  public function getFullName() : String {
    return firstName + " " + lastName;
  }
}

Check out the Granite Data Services project for Java -> AS3 code generation.

http://www.graniteds.org

cliff.meyers