5.2 Editing

5.3 Creating a New Diagram

To create a new diagram use Diagrams:New Diagram... in the source browser. Below the command New BETA program has been used:

[8kb 483x222 GIF]

The title of the diagram corresponds to the name and the category (attributes) of the new BETA fragment:

ORIGIN '~beta/basiclib/betaenv';
INCLUDE '~beta/freja/associations';
-- lib: Attributes --
<<NameDecl>>: (#  #)

5.3.1 Creating a New Class

When an attribute or a title of a diagram is selected it is possible to create a new class using the Class command in the New menu [tip: you may also right-click the class or attribute and select New:Local Class... from a popup-menu]. Doing this you get a dialog where the name of the new class can be typed in.

[8kb 391x299 GIF]

The BETA code corresponding to new class looks like this:

Person:(# #)

5.3.2 Adding Attributes and Operations

To add an attribute to a class, select the class and use New:Attribute... [tip: you may also right-click the class and select New:Attribute... from a popup-menu]. As above a dialog is presented and you can now type in the name of the new attribute.

[8kb 406x224 GIF]

The corresponding BETA code looks like this:

Person(# FirstName: @Text #)

In the same manner as with attributes a new operation "display" can be added to the class using New:Operation.... This makes the diagram appear as follows:

[8kb 483x222 GIF]

Notice the first item in the diagram, <<NameDecl>>() ..., is still there. This is meant as first template for a new class (the <<NameDecl>> part is a placeholder for the name of the class). In this case, where we have already created a new class using New:Class..., we could just delete this first item by selecting it and using Edit:Clear. However, we can also choose to use it as a template for a new class. To do this, select it and use the Edit... entry of the right-click popup-menu to replace "<<NameDecl>>" with the name "Reservation".

5.3.3 Specifying Specialization

In the following situation one class further, FlightReservation, has been added to the diagram. To specify that FlightReservation is a subclass of Reservation the Specialization command of the Relations menu is used. As the status message of the menubar states in the example below it is now possible to create a specilization by clicking the left mouse button on the subclass and hereafter clicking the right mouse button on to the superclass.

[10kb 579x356 GIF]

The result will look like this:

[10kb 579x356 GIF]

The code correspondingly changes from:

Reservation: (# ... #);
FlightReservation: (# ... #);

to:

Reservation: (# ... #);
FlightReservation: Reservation(# ... #);

5.3.4 Specifying Aggregation

Below the class Flight has been added to the diagram.

[11kb 714x329 GIF]

We wish to specifify a by-reference aggregation between FlightReservation and Flight. To do this select Aggregation in the Relations menu. This brings up the following dialog:

[10kb 421x424 GIF]

The aggregation dialog makes it possible to:

In this example we only specify the name of the aggregation (defaults are such that we get a one-to-one by-reference aggregation).

After choosing Ok in the dialog left click on the class designating the whole (FlightReservation) and, after that, right click on the class designating the part (Flight).

[12kb 714x329 GIF]

The BETA code correspondingly changes from:

Flight: (# #);
FlightReservation: Reservation(#  #)

to:

Flight: (# ... #);
FlightReservation: Reservation(# theFlight: ^Flight #)

As can be seen the name of the aggregation is reused in the code and the fact that we created a by-reference aggregation is reflected by the dynamic reference implementation of the new declaration (had we instead chosen by-value a static reference would have been declared).

5.3.5 Specifying Association

Below a new class Company has been added to the diagram.

[12kb 714x329 GIF]

We wish to specify a one-to-many association between Company and Person. To do this select Association in the Relations menu. This brings up the following dialog:

[10kb 421x424 GIF]

The Association dialog makes it possible to:

In this example we specify the name of the association, WorksFor, the name of the source role, employee, the name of the destination role, employer, and the multiplicities. Specifying that the multiplicity of the employee end of the association is more than one (in this case '*') automatically sets the implementation to the default, List.

After choosing Ok in the dialog left click on the class designating the source (Person) and right click on the class designating the destination (Company).

[13kb 714x329 GIF]

The resulting code looks like this:

Person: (# ...; employer: ^WorksFor #);
Company: (# employee: ^WorksFor #);
WorksFor: OneToManyAssociation
  (# oneType:: Company; manyElmType:: Person #)

Where the things added to code are the employer and employee declarations and the WorksFor class.

Had the embed option been chosen the code would have looked like this:

Person: (# ...; employer:@AssociationOne(# element:: Company #) #);
Company: (# employee:@AssociationMany(# element:: Person #) #)

Notice that in this case no separate association class is generated.

5.3.6 Completing the Code in Code Editor

Consider the following design diagram which could be considered as complete at the design level:

[20kb 851x703 GIF]

To fill out the code details, the code editor, the textual representation editor must be activated:

[18kb 717x553 GIF]

The textual representation of the design might, however, not be complete. For example, it still contains operations with empty do-parts. To fill out the do-part of the getFlightNo operation in the FlightReservation Class select the entire getFlightNo pattern in the code editor. Enter text edit mode and type in the appropriate action sequence. For example:

getFlightNo:
  (#
     do theFlight.no->putint
   #)
Notice: When entering text edit mode with the entire getFlightNo pattern selected we are warned that such editing might have the consequence that parts of the diagram have to be rebuildt. In this case, however, we choose to ignore the warning and enter text edit mode anyway. As it turns out the diagram was not affected at all by the edit because only a do-part was changed (action sequences do not have a visual representation in the diagrams; only static structures have).

After filling out more code in the code editor, e.g. further action sequences of the objects, the compiler is activated in the Compile/Run menu of the code editor.

If the compiler reports a semantic error, the corresponding node is also selected in Freja.

When the program is semantically correct and it can be executed and tested. In this phase Freja will typically not be activated. When the program has been tested and considered fulfilling the requirements, the design diagrams may have become obsolete, and need to be updated, i.e. reverse engineering is necessary. This is done by activating Freja on the BETA program.


[1] An aggregation is said to be one-to-many if the multiplicity of the part is one and the multiplicity of the whole is more than one


Mjolner Integrated Development Tool - Tutorial
© 1991-2002 Mjølner Informatics
[Modified: Friday October 27th 2000 at 15:05]