Suppose I use the [RemoteClass] tag to endow a custom Flex class with serialization intelligence.
假设我使用[RemoteClass]标签赋予自定义Flex类以及序列化智能。
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?
是否有一种设计模式以优雅的方式处理它?
2 个解决方案
#1
3
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:
最好的办法是针对后端类生成代码,以便为它们生成ActionScript副本。如果您生成一个包含所有对象属性的基类,然后为它创建一个永远不会被修改的子类,您仍然可以添加自定义代码,同时仅重新生成更改的类的部分。例:
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.
查看用于Java的Granite Data Services项目 - > AS3代码生成。
#2
1
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.
我喜欢使用显式数据传输对象,而不是保留我在整个应用程序中使用的实际数据模型。然后,您从DTO-> Model的翻译可以考虑版本差异。
#1
3
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:
最好的办法是针对后端类生成代码,以便为它们生成ActionScript副本。如果您生成一个包含所有对象属性的基类,然后为它创建一个永远不会被修改的子类,您仍然可以添加自定义代码,同时仅重新生成更改的类的部分。例:
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.
查看用于Java的Granite Data Services项目 - > AS3代码生成。
#2
1
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.
我喜欢使用显式数据传输对象,而不是保留我在整个应用程序中使用的实际数据模型。然后,您从DTO-> Model的翻译可以考虑版本差异。