Duality of Objects and Values

Duality of objects and values allows looking at a modeling system as a set of collaborating objects, and the same time operate object states in some data approach like relation model and SQL.

An object can have collaborators and state. Collaborators are objects, object state is a value. In similar way, in message implementations local names (variables) can be either objects or values.

Messages return strictly values, and message parameters are strictly objects.

Conceptually, reading and writing some value (in general sense) differ in their nature: writing requires validation, but reading does not (I generalized the requirement of writing validation: since some value can be written to a variable, this value may be wrong). Both (reading and writing) may also require such features like authorization, filtering, confidentiality etc., but validation is a property of writing.

The idea is to apply CQRS for manipulating objects. Messages are the way to change object state (and provide validation), while reading object state is a separated Paml feature. Variables can be either of object type or value type. There is symmetrical mechanism for this duality: a variable can be declared as an object to send messages, or as a value to read its state and look at the object as data (with possible relations in SQL style).

Keyword dataOf takes an object and switches its "view" to state data, which is a value. With this value reading operations are possible. Keyword objectOf takes a value and switches its "view" to corresponding object for sending messages. The variables passed into the keywords are join point: transformations will define how and what is used exactly in expressions.

The keywords dataOf and objectOf are not actually like functions, they are just syntax to switch how an object is considered: as an object for sending messages or as data for reading its state values.

Local variables are declared with val and obj keyword that declare some value or object respectively. Then variables are manipulated with dataOf and objectOf operations.

There is a topic about assigning properties by some values in GPL like C#. An assign operation is naturally low-level operation and very abstract. In Paml, objects do not have properties or fields at all. So changing even a single state item requires a message. This seems that even simple assignment operations will have a meaning name. For example, if there is object Circle and it has Radius state item, in order to change only the radius a message is required, and seems Resize name is well for it.

Code example

object Alonzo . Drawing . Circle
data Radius : double;
message Resize ( radius : double )
"this" is required to access object state via data access operator "."
this.Radius = radius;
Since parameter name is required in sending a message, is it possible to overload messages by parameter names but not by parameter types like in C#?
message Resize ( delta : double )
this.Radius += delta;
subject Alonzo . Drawing . Painter
data Circles : Circle[]; The type is inferred as Alonzo.Drawing.Circle
message Render
"circle" is an object, only message sending is possible via object access operator "->"
obj circle; The type is inferred as Alonzo.Drawing.Circle
Parameter name is required. As result, the order of parameters is free.
circle->Resize ( radius: 60 );
val radius = 300.0;
The local variable matches the parameter so parameter name is inferred as "radius"
circle->Resize ( radius );
val cir = dataOf ( circle ) ;
radius = cir.Radius;
objectOf ( cir ) -> Resize ( radius : 600 );
obj circle2 = objectOf ( cir ) ; "circle" and "circle2" are actually the same object.
circle2 -> Resize ( delta : 600 ); Overloading call by parameter name

Write a comment

Comments: 0

Pallada project, Copyright © 2015 - 2021.

For any mentions and citations of the site materials, a link to the Pallada project site is obligatory.