I want to know if there are disadvantages / disadvantages of using value objects when initializing an object, for example:
public class MonsterVO { public var tenticles : Boolean; public var growl : GrowlType; public var damage : int; public var health : int; } public class Monster { private var tenticles : Boolean; private var growl : GrowlType; private var damage : int; private var health : int; public function Monster(monsterData : MonsterVO) { tenticles = monsterData.tenticles; growl = monsterData.growl.clone(); damage = monsterData.damage; health = monsterData.health; } }
If you plan to use and initialize your domain object in the Monsteronly way (from the DTO MonsterVO), there are no problems. But how can you be sure that in the future there will be no other applications? You cannot overload the constructor in ActionScript (for example, in Java). What if you need to create a clone? You will need to create a fake one MonsterVOfor this :(
Monster
MonsterVO
I think it is better to create some Factory method to solve your problem.
fa Factory, , , , .
, .
, , , , VO. ( Factory , DI)
public function configure(config:MonsterVO):void { for (var prop :String in config) { if ( config[prop] != null && this.hasOwnProperty(prop) ) this[prop] = config[prop]; } }