134
Specication Techniques
The multiplication of Example 7.8 has been shown in Fig. 7.28. To perform multiplication, rst values are placed at places p1 and p2 . Thus, data transitions q1 and q2 are enabled. Firing them leads to movement of the two values to the places p3 and p4 . Some operations mapped onto data transitions require a control signal to be activated. For example, transition q4 is enabled when p4 holds a token.
Fig. 7.28 Dual transitions Petri Net structure of multiplier algorithm.
7.5
Unied Modelling Language (UML)
The Unied Modelling Language (UML) was originally proposed for modelling complex, software intensive systems. It provides quite a few advantages over SDL. It is less formal, and thus can be used at an early stage to structure and analyse the concepts of an application domain before the functional design is made. SDL does not support relations in object modelling. Thus, UML can be used to develop the formal functional design in SDL using the object models of UML. UML is a graphical language consisting of dierent types of diagrams that can be used to describe a model from dierent angles. The diagrams can be classied into three categories: Behaviour diagramsdescribing behavioural features of a system. This includes activity, state machine, use case, as well as the following four interaction diagrams. Interaction diagramsa subset of behaviour diagrams emphasizing object interactions. This includes communication, interaction, overview, sequence, and timing diagrams. Structure diagramsdepict the elements of a specication that are irrespective of time. The constituents are class, composite structure, component, deployment, object, and package diagrams. In the following subsections, we briey describe each of these diagrams.
7.5 Unied Modelling Language (UML)
135
7.5.1
Activity Diagram
This represents the operational step-by-step workows of components in a system. It gives the overall ow of control. UML activity diagrams may be considered as object-oriented equivalent of ow charts and data ow diagrams. Thus, it often consists of dierent types of components as shown in Fig. 7.29.
Fig. 7.29 Notations in activity diagrams. Figure 7.30 shows an example activity diagram for creating a user in a library system. The user lls up a form (hard copy) which is checked for correctness. If found correct, a screen is displayed to the user to enter details. A new user-name (id) and a password are also created.
7.5.2
Class Diagram
This is the main part of object-oriented analysis and design in UML. It can be used to show classes in the system, their interrelations, operations, and attributes. A class is shown as a rectangle with three compartmentsname of the class, attributes and operations. For example, Fig. 7.31 shows an example class Door with a single attribute status of type String, initialized to closed. It has two operations dened on it Open() and Close(). An object is an instance of a class. A UML object is represented by a rectangle with one or more compartments like class. Figure 7.32 shows an object D of class Door. Many kinds of relationships can be modelled in UML. These are as shown in Fig. 7.33. An association denes a relationship between two or more classes resulting in binary- or n-ary relations respectively. Aggregation models the whole/part relationship. A dependency is a relationship that indicates that a model element is in some way dependent on another model element. Generalization is a relationship between a more general element (superclass) and a more specic element (subclass). It can be used to dene inheritance/hierarchy as shown in Fig. 7.34.
136
Specication Techniques
Fig. 7.30 An activity diagram showing user creation in a library system.
Fig. 7.31 An example class.
Fig. 7.32 An example object.
7.5.3
Communication/Collaboration Diagram
UML 2 communication diagrams (known as collaboration diagrams in UML 1.x) are used to show objects and messages involved in accomplishing a purpose or a set of purposes. The message sequence is identied by the sequence numbers. Format of a message is as follows: precondition/sequence-number [ expression ] : return-value := message-name(parameter-list) Figure 7.35 shows a collaboration diagram showing the messages passed between a library user and the various components of the library system.
7.5 Unied Modelling Language (UML)
137
Fig. 7.33 Relationships among UML classes.
Fig. 7.34 Inheritance among UML classes.
Fig. 7.35 An example communication/collaboration diagram.
7.5.4
Component Diagram
Component diagrams depict how a system is split up into components. They also show the dependency between the components. Figure 7.36 shows a component diagram with ports and interactions.
138
Specication Techniques
Fig. 7.36 An example component diagram.
7.5.5
Use Case Diagram
These diagrams give an overview of the usage requirements for a system. They show relationships among actors and use cases. An actor is a role of an object or objects outside the system that interacts directly with it in a use case. It has class-like properties. A use case is a unit of functionality of the system or a class. There can be three dierent types of associations between actors and use cases as follows: 1. Communicates: Shows participation of an actor in a use case. It is shown as a solid line, and is the only possible relationship between actors and use cases. 2. Extends: It is a relationship from use case A to use case B , indicating that an instance of use case B may include the behaviour of use case A. It is shown as a generalization arrow labeled with << extends >>. 3. Uses: It is also a relationship from use case A to use case B indicating that an instance of use case A will also include the behaviour specied by use case B . This is also shown as a generalization arrow labeled with << uses >>. Figure 7.37 shows an example of use case diagram.
Fig. 7.37 An example use case diagram.
7.5.6
Sequence Diagram
Sequence diagram of a system shows some simple interactions between objects arranged in a time-sequence. For each object, a life-line is shown. Exchange of messages between the objects are also represented. When an object is not active, its lifeline is shown as a dashed line. During active period, the life-line is represented as a thin rectangular bar. An object may become
7.5 Unied Modelling Language (UML)
139
active and inactive several times in its life-span. The life-span of an object may be terminated by putting a at the end of a life-line. Messages are shown as arrows labeled with name of the message and parameters, if any. Figure 7.38 shows an example sequence diagram.
Fig. 7.38 An example sequence diagram.
7.5.7
Other Diagrams
UML contains some more diagrams, which are not very much used in specications, however, may be utilized to bring clarity to the specication. These are briey described below: 1. Composite structure diagram: This is used to describe the internal structure of a class. It can include internal parts, ports, etc. 2. Deployment diagram: The deployment diagram of a system models the hardware used in system implementations, components deployed on the hardware and the association between these components. 3. Interaction overview diagram: These are variants of UML activity diagrams showing control ow. Nodes within this diagram are frames, rather than normal activities. Frames can depict any type of UML interaction diagrams (like sequence diagrams, communication diagrams, timing diagrams, etc.). 4. Object diagram: An object is an instance of a class. Object diagrams are similar to the class diagrams excepting the fact that these can be used to explain complex relationships between classes. Objects belonging to the same class may now be associated with objects of other classes in dierent ways. 5. Package diagram: Packages enable us to organize elements into groups. These can be used in conjunction with any of the UML diagrams just like le folders.
140
Specication Techniques
6. State machine diagram: This is similar to StateCharts discussed earlier. This can be used to capture state-based behaviour of a system. 7. Timing diagram: These can be used to explore the behaviour of one or more objects throughout a given period of time. The time may be represented as various phases of system operation in embedded system design.
7.5.8
UML Specication of an Elevator Control System
Let us consider a system to control elevators in a building with m oors. We need to move elevators between oors according to a set of constraints, as follows: 1. Each elevator has a set of m buttons, one for each oor. These can be pressed to cause the elevator to stop at that oor. The buttons also illuminate when pressed, and are turned o when the oor is reached. 2. Each oor excepting the rst and top, has two buttons, one to request up, the other to request down. These buttons also illuminate when pressed and are turned o when an elevator visits that oor and moves in the desired direction. 3. In case there are no requests, an elevator remains at its current oor with door closed. The detailed class diagram from the system has been shown in Fig. 7.39. The collaboration diagrams have been shown in Figs. 7.40(a) and (b) respectively. The sequence diagram has been shown in Fig. 7.41.
Fig. 7.39 Class diagram.
7.5 Unied Modelling Language (UML)
141
Fig. 7.40 Collaboration diagrams for serving.
Fig. 7.41 Sequence diagram for elevator operations.