Download Interaction and State Diagrams in Object-Oriented Software Engineering and more Slides Banking and Finance in PDF only on Docsity!
Object-Oriented Software Engineering
Practical Software Development using UML and Java
Chapter 8: Modelling Interactions and Behaviour
8.1 Interaction Diagrams
Interaction diagrams are used to model the dynamic aspects of a software system
- They help you to visualize how the system runs.
- An interaction diagram is often built from a use case and a class diagram. —The objective is to show how a set of objects accomplish the required interactions with an actor.
Elements found in interaction diagrams
- Instances of classes —Shown as boxes with the class and object identifier underlined
- Actors —Use the stick-person symbol as in use case diagrams
- Messages —Shown as arrows from actor to object, or from object to object
Creating interaction diagrams
You should develop a class diagram and a use case model before starting to create an interaction diagram.
- There are two kinds of interaction diagrams: — Sequence diagrams — Communication diagrams
Sequence diagrams
A sequence diagram shows the sequence of messages exchanged by the set of objects performing a certain task
- The objects are arranged horizontally across the diagram.
- An actor that initiates the interaction is often shown on the left.
- The vertical dimension represents time.
- A vertical line, called a lifeline , is attached to each object or actor.
- The lifeline becomes a broad box, called an activation box during the live activation period.
- A message is represented as an arrow between activation boxes of the sender and receiver. —A message is labelled and can have an argument list and a return value.
Sequence diagrams –
same example, more details
Sequence diagrams –
an example with object deletion
- If an object’s life ends, this is shown with an X at the end of the lifeline
Communication diagrams – an example
Communication diagrams –
same example, more details
Communication links
- A communication link can exist between two objects whenever it is possible for one object to send a message to the other one.
- Several situations can make this message exchange possible: 1. The classes of the two objects have an association between them. - This is the most common case. - If all messages are sent in the same direction, then probably the association can be made unidirectional.
Other communication links
- The receiving object is global.
- This is the case when a reference to an object can be obtained using a static method.
- The stereotype «global», or a [G] symbol is used in this case.
- The objects communicate over a network.
- We suggest to write «network».
How to choose between using a sequence
or communication diagram
Sequence diagrams
- Make explicit the time ordering of the interaction. —Use cases make time ordering explicit too —So sequence diagrams are a natural choice when you build an interaction model from a use case.
- Make it easy to add details to messages. —Communication diagrams have less space for this
Communication diagrams and patterns
A communication diagram can be used to represent aspects of a design pattern
8.2 State Diagrams
A state diagram describes the behaviour of a system , some part of a system, or an individual object****.
- At any given point in time, the system or object is in a certain state. —Being in a state means that it is will behave in a specific way in response to any events that occur.
- Some events will cause the system to change state. —In the new state, the system will behave in a different way to events.
- A state diagram is a directed graph where the nodes are states and the arcs are transitions.