Presentation is loading. Please wait.

Presentation is loading. Please wait.

System Sequence Diagrams

Similar presentations


Presentation on theme: "System Sequence Diagrams"— Presentation transcript:

1 System Sequence Diagrams
Chapter 10 System Sequence Diagrams

2 Fig. 10.1

3 Fig. 10.2

4 Fig. 10.3

5 Fig. 10.4

6 Fig. 10.5

7 Chapter 15: UML Interaction Diagrams

8 15.1 Introduction Interaction diagrams illustrate how objects interact via messages to carry out tasks: they model the dynamic aspect of objects. 2 types of interaction diagrams: Sequence interaction diagrams; Communication interaction diagrams; We will only focus on sequence diagrams.

9 15.2 Sequence and Communication Diagrams
Both kind of diagrams have the same role within the UML. UML modeling tools allow the software engineer to translate one style into the other style : they are equivalent. Hence : use whatever style you like; Sequence diagrams emphasise the order of messages between objects (communication diagrams rely on numbering of the messages); Communication diagrams are more space efficient, especially if many objects are involved; Example of a sequence diagram :

10 Skeleton sample code for the previous example:
public class A { private B myB = new B(); public void doOne() myB.doTwo(); myB.doThree(); } // … Equivalent communication diagram:

11 Another Sequence Diagram : makePayment
Which can be read as follows: The message makePayment is sent to an instance of a Register. The sender is not identified. The Register instance sends the makePayment message to a Sale instance. The Sale instance creates an instance of a Payment.

12 Code for the makePayment method of the Sale Class:
public class Sale { private Payment payment; public void makePayment( Money cashTendered ) payment = new Payment( cashTendered ); //… } // …

13 15.3 Interaction Diagrams and Class Diagrams
Most of the effort during OOD should be spent on creating interaction diagrams not the class diagram: Interaction diagrams are much more valuable : they detail the algorithms for each method; dynamic view; A class diagram is just a summary; static view; it is very easily created after the interaction diagrams; Coding will be much easier from the interaction diagrams since they detail the many design decisions that have been made; class diagrams show the structure of the classes’ organization; Jumping from the analysis to the class diagram directly is hard; Jumping from the class diagram to coding is hard; Interaction diagrams are an intermediary step between analysis and design, and also between design and coding: they are very valuable.

14 15.4 Common UML Interaction Diagram Notation
Lifeline Boxes :

15 Message syntax : Singleton objects : Examples:
return = message(parameter : parameterType) : returnType Examples: initialize(code) Initialize d = getProductDescription(id) d = getProductDescription(id:ItemID) d = getProductDescription(id:ItemID) : ProductDescription Singleton objects : As we will see later when looking at the singleton pattern, it is very common to deal with the case when only one instance of a class will ever be instantiated (never two) in an application. In this case the singleton pattern can be used to gain visibility to the object. In a UML interaction pattern such an object is marked with a ‘1’ in the upper right corner of the lifeline box. See Figure 15.1 for an example.

16 15.5 Basic Sequence Diagram Notation Messages :
Figure 15.1 Singletons in Interaction Diagrams 15.5 Basic Sequence Diagram Notation Messages :

17 Many of the details of the notation are optional and are only typically shown whenever using a CASE tool to create the diagrams. Optional elements include: The execution specification bar; The solid bar on a found message; The type information of messages; Using an agile approach, it is reasonable not to show these features except maybe the type information which is useful. Message returns : There are two ways to show the return result from a message: Using the message syntax return Var = message(parameter). Using a reply message line at the end of an activation bar. For an example see Figure 15.2

18 Messages to ‘self’ or ‘this’ :
Figure 15.2 : Two Ways to Show a Return Result from a Message Messages to ‘self’ or ‘this’ :

19 Creation of instances :
Typically we use the language independent create message:

20 Object Lifelines and Object Destruction
We may show the explicit destruction of an object

21 Frames in UML Sequence Diagrams :
To allow the visualization of complex algorithms, sequence diagrams support the notion of frames; Frames are regions of the diagrams that have an operator and a guard,. Figure 15.3:

22 Typical frame operators are:
Semantics alt Alternative fragment for mutual exclusion conditional logic expressed in the guards. loop Loop fragment while guard is true. Can also write loop(n) to indicate looping n times. opt Optional fragment that executes if guard is true. par Parallel fragments that execute in parallel. region Critical region within which only one thread can run. Figure 15.3 illustrated the use of a loop frame; Figure 15.4 illustrate the use of an opt frame:

23 Figure 15.4 Using the opt Frame
Figure 15.5 illustrate the use of the alt frame for mutually exclusive alternatives

24 Iteration Over a Collection :
Figure 15.5 Using the alt Frame Iteration Over a Collection : A common algorithm is iterate over all members of a collection (any data structure) sending the same message to each object: See figure 15.6 and 15.7 for possible visual representations

25 Figure 15.6 Iteration Over a Collection Using Explicit Notation
Figure 15.7 Iteration Over a Collection Using Implicit Notation

26 Nesting of Frames : Frames can be nested:

27 More Sequence Diagrams and Contracts
Chapter 32 More Sequence Diagrams and Contracts

28 Fig. 32.1

29 Fig. 32.2

30 Fig. 32.3


Download ppt "System Sequence Diagrams"

Similar presentations


Ads by Google