Reading and Updating Attributes Tech Note - modelint/shlaer-mellor-metamodel GitHub Wiki

mint.sm-meta.action.tn.1 / Leon Starr / Version 0.3.1 / 22-2-6

Let's start simple by reading and writing values from and to class model attributes.

Reading attributes

We can read the values of multiple attributes using the Read attributes primitive action.

images/action/tn1-10.png

This primitive action can read multiple attribute values of a single instance. Since instance data is populated as a class table, it makes sense that you would output a table value.

In Scrall we could assign the output to a tuple:

atcinfo |= some atc.(Name, Rating)

The variable/flow atcinfo is a single row table (tuple) with the headers Name:Name and Rating:Experience Level. A tuple value will be shown in our example data flow diagrams as a flow terminating with a double bar.

Most of the time what you really want is a scalar value (no table heading, just a single value). This can be achieved by adding a primitive to extracts a scalar for a given attribute from the tuple.

images/action/tn1-20.png

Here the Scrall would be:

atc name = some atc.Name

To extract multiple scalar values we use an instance of the extract process for each value:

images/action/tn1-30.png

And write in Scrall:

atc name, atc rating = some atc.(Name, Rating)

Writing (updating) attributes

We can use the update primitive introduced in tn4 to update any set of attributes belonging to the same class.

images/action/tn1-40.png

The Scrall for this action could be:

atc update tuple |= Rating: in.new rating, Eyesight correction: in.latest eyesight status
atc to update.(Rating, Eyesight correction) = atc update tuple

The above could have been written in one line without the need for an intermediate tuple variable, but it still looks a bit heavy handed. Unless we want that variable for some kind of table operation, which we don't in this case, it is easier to just apply the scalar values directly. We can use a sequence to apply each value to the correct class model attribute.

We can use a primitive to generate the tuple and then feed it into the update primitive.

images/action/tn1-50.png

In the usage example we take two input parameters and combine them into a tuple. A mapping from each flow name to a corresponding attribute name is specified so that the tuple can be constructed.

The corresponding Scrall looks like this:

atc to update.(Rating, Eyesight correction) = in.new rating, in.latest eyesight status

Going a step further, as we did with the update action, we can create a composite action that hides the tuple construction step as shown:

images/action/tn1-60.png