AS3 中的值对象和通用类有什么区别?
我不明白 ActionScript3 中的值对象和类之间在结构上有何不同。
如果您决定将任何类称为 VO,那么它可以是 VO 吗?
谢谢。
I don't understand what is structurally different between a Value Object and a Class in ActionScript3.
Can any Class be a VO if you decide to call it one?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
动作脚本类可以包含字段(var)、属性(getter/setter)和方法。术语“值对象”是指框架(例如 Cairngorm)用于存储的类并在组件和模块之间传递数据。这些类充当保存数据的模板,通常不包含除 getter/setter 之外的函数。
Cairngorm 框架有一个 IValueObject 接口,该接口不支持不包括任何方法。
值对象是动作脚本中的一个宽松术语。 此处的 AS3 语言参考已使用此术语来表示对象传递给类的构造函数来初始化其属性。
使用值对象使类的用户能够仅初始化他们希望初始化的属性。此方法的另一种替代方法(在我看来更健壮且不易出错)是将每个属性指定为构造函数的参数并为其分配默认值。
An actionscript class can include fields (vars), properties (getters/setters) and methods. The term value object refers to classes used by frameworks (such as Cairngorm) to store and pass data among components and modules. These classes act as templates to hold data and generally won't contain functions other than getters/setters.
The Cairngorm framework has a IValueObject interface that doesn't include any methods.
Value object is a loose term in actionscript. The AS3 language reference here has used this term for an object that's passed to the constructor of a class to initialize its properties.
The use of value object enable the users of the class to initialize only those properties that they wish to. An alternative to this method (more robust and less error prone one imo) is to specify each property as arguments to the constructor and assign default values to them.