Deepclone
(Created page with "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 t...")
 
No edit summary
Line 8: Line 8:
[[File:Deepclonedefinition.png|none|thumb|815x815px]]
[[File:Deepclonedefinition.png|none|thumb|815x815px]]
Then in OCL you do;
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.


self.deepclone('ViewModel_Person_DeepClone')
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.
 
The deepclone operator returns the new Person object, complete with copies of OwnedBuildings and the Home links.

Revision as of 12:28, 20 May 2017

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;

Simpleclassstructure.png

We let a viewmodel act as a definition for what the clone should do,, like this for example;

Deepclonedefinition.png

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.

This page was edited 96 days ago on 02/10/2024. What links here