Deepclone
This page was created by Lars.olofsson@mdriven.net on 2017-05-20. Last edited by Stephanie@mdriven.net on 2025-02-13.

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.

MDriven Chat

How would you like to chat today?

Setting up your conversation…

This may take a few moments