Reverse Derivation

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.

image

image

image

And it will give me this:

image

 

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:

image

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:

image

here comes the same EAL as text:

let parts=vInputParameter.Split(' '.ToCharArray().At0(0)) in
(
  self.GivenName:=parts.At0(0);
  self.Surname:=parts.At0(1)
)

 

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:

2017-06-12_10h59_33

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.

This entry was posted in CO-Unique, MDrivenDesigner, OCL and tagged , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*