2009/11/17 Rickard Öberg <[email protected]> > On 2009-11-17 23.07, Jacek Sokulski wrote: > >> In cases where I want to have the state private per role, e.g. Person >> can have two roles HasName and HasSpouseName and implementation for both >> use NameState. >> > > But for the marriage-side you wouldn't do that as a single role. The entity > itself would be Marriable, and then if you want to model multi-marriage > situations, then keep two MarriedToValues. > > And is it possible for a person to have two names? Well, if it is, then do > the same as above. If your domain is complex, don't try to simplify it down. > But Qi4j can handle it, with the above concept. > > It was contrived example and, sure, you can model it with VOs or other means, but it is not the point. State is public per composite so in implementation/reusability unit (role mixin) I do not have control of it, in other words the state is a kind of global data. The state carries a very definite semantics and if two roles uses the same state assuming different semantics it can lead to vicious bugs. It is especially true if one is composing entity from existing roles without knowledge of the implementation.
Maybe it is just bad practice to share inner state directly between roles (although I think this way it is done in some examples), and each role should have its private state or share it only with a strongly coupled (semantically) roles.
_______________________________________________ qi4j-dev mailing list [email protected] http://lists.ops4j.org/mailman/listinfo/qi4j-dev

