Reference management for association classes
The referential attributes that formalize an association may reside in an association class. In this case references are managed by creating and deleting instances of the association class.
In this example we have a Torpedo associated with a Target:
In some state of Torpedo, it acquires a new Target:
new target .= Target( ID: in.new target ID ) &R3 new target( Bearing to target: compute heading( new target.Location ), Range to target: dist to target( new target.Location ) )
The format to use for setting a new reference using an association class is this: The format to use for setting a new reference using an association class is this:
[<source instance>] &<rname> <target instance>[(attr init list)]
In our example, the source instance is omitted, so the local instance is assumed. The target is looked up in the first line and assigned to the coincidentally named
new target instance set variable. This is then plugged in as the target instance and used to access its Location attribute for two local methods that compute initial values for the association class attributes.
So, basically, you just supply the relationship name, the instance you want to refer to and then initialization values for the newly created instance of the association class. You don’t need an explicit
*Target Acquisition() creation action since this is implied by the need to create a reference.
Alternatively, you could have set the references to Torpedo and Target with with a single creation action:
*Target Acquisition( Torpedo: ID, Target: in.new target ID, Bearing to target: compute heading( new target.Location ), Range to target: dist to target( new target.Location ) )
The result is the same.