To create a new diagram use Diagrams:New Diagram... in the source browser. Below the command New BETA program has been used:
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>>: (# #)
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.
The BETA code corresponding to new class looks like this:
Person:(# #)
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.
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:
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".
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.
The result will look like this:
The code correspondingly changes from:
Reservation: (# ... #); FlightReservation: (# ... #);
to:
Reservation: (# ... #); FlightReservation: Reservation(# ... #);
Below the class Flight has been added to the diagram.
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:
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).
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).
Below a new class Company has been added to the diagram.
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:
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).
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.
Consider the following design diagram which could be considered as complete at the design level:
To fill out the code details, the code editor, the textual representation editor must be activated:
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:
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).
getFlightNo: (# do theFlight.no->putint #)
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.
Mjolner Integrated Development Tool - Tutorial | © 1991-2004 Mjølner Informatics |
[Modified: Friday October 27th 2000 at 15:05]
|