Log in

Reverse Derivation

From MDrivenWiki

Derivation is when you provide an ocl expression in the definition of an Attribute of AssociationEnd. This expression is then the definition of the content of this object member.

Derivations are very powerful and remove the need for repeating definitions multiple times.

Example; a person has a given name and a surname but I often want to display them together as Fullname.

Reverse derivation - 1.png

Reverse derivation - 2.png

Reverse derivation - 4.png

And it will give me this:

Reverse derivation - 5.png

The only snag with this is that Full Name show up as read only. Read only is a consequence of being derived.

This is where Reverse Derivation comes into play. If I want the Full Name to be editable I will need to parse the result and split it into a Given Name and a Surname. For this parsing I will need some logic.

I can change the AttributeMode from Derived to DerivedSettable:

Reverse derivation - 6.png

When I do a new property shows up DerivationOclSet. This ocl is written in EAL(Action language) and can change data (have side effects).

I will implement the string parsing of the FullName like this:

Reverse derivation - 7.png

here comes the same EAL as text:

let parts=vInputParameter.Split(' '.ToCharArray().At0(0)) in

The value the user supplies comes in the vInputParameter. I split this on blank-character (slit expects a char and ocl deals with strings so I convert the string to an array of chars and grab the first one). I now have a collection of hopefully 2 strings – one I assign to GivenName and one I assign to Surname.

It will give med this:

Reverse derivation - 8.gif

The FullName is editable – and when a user changes it – the set-expression is executed – that in turn updates the parts that build up the FullName – that then is re-derived and gets updated.

This works on attributes – not derived associations.