Hans Karlsen (talk | contribs) No edit summary |
Hans Karlsen (talk | contribs) No edit summary |
||
Line 13: | Line 13: | ||
A good place to use this operator is in a method on a class, for example CreateClone() : Person. That way you just call self.CreateClone from a class action using the returned object as the root of the viewmodel the action opens. | A good place to use this operator is in a method on a class, for example CreateClone() : Person. That way you just call self.CreateClone from a class action using the returned object as the root of the viewmodel the action opens. | ||
Also see the OCLOperators_transform operator that is a a DeepClone that can change type. | Also see the [[OCLOperators_transform]] operator that is a a DeepClone that can change type. | ||
[[Category:OCL]] | [[Category:OCL]] | ||
[[Category:Operators]] | [[Category:Operators]] |
Revision as of 09:01, 30 September 2021
Pretty often you have user scenarios that require you to copy an existing object structure. Like when handling revisions of things and the user wants a new revision but want to start with the old and just tweak a few values.
In cases like these it would be neat with a clone mechanism of your modeled objects. And once you have a clone mechanism you pretty soon will discover that cloning just one object will not suffice – you want to follow associations and clone owned child objects – but only in some cases – in other cases you don’t want to clone the child objects but rather reference the same ones from the clone.
Given this model;
We let a viewmodel act as a definition for what the clone should do,, like this for example;
Then in OCL you do;
self.deepclone('ViewModel_Person_DeepClone')
The deepclone operator returns the new Person object, complete with copies of OwnedBuildings and the Home links.
A good place to use this operator is in a method on a class, for example CreateClone() : Person. That way you just call self.CreateClone from a class action using the returned object as the root of the viewmodel the action opens.
Also see the OCLOperators_transform operator that is a a DeepClone that can change type.