1 / 46

Chapter 15

Chapter 15. Interaction Diagrams. Most Common. Sequence Diagram Communication Diagram Sequence Diagrams illustrate interactions between classes of a program using class methods as message names,. Sample Code:. public class A { private B myB = null; public A () {

Download Presentation

Chapter 15

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter 15 Interaction Diagrams

  2. Most Common • Sequence Diagram • Communication Diagram • Sequence Diagrams illustrate interactions between classes of a program using class methods as message names,

  3. Sample Code: public class A { private B myB = null; public A () { myB = new B(); } public void doOne() { myB.doTwo(); myB.doThree(); } }

  4. Fig. 15.1 duration of doOne() activity

  5. Fig. 15.2 Communication Diagram sequence numbers Same interaction in a “network” diagram description

  6. Strengths and Weaknesses • UML has put more thought into SDs • Better tool support for SDs • Better at showing “sequence” • CDs are more space efficient, boxes can go anywhere • Easier to modify a CD • CDs are “vertical” so fit on narrow pages of a book

  7. Fig. 15.3 lifeline NOTE: If you need to extend you’ve run out of space

  8. Fig. 15.4 NOTE: If you need to extend you can come back to the left.

  9. Static vs Dynamic View • The Class Diagram is a static view of the program while the Sequence Diagram is a dynamic view. Both are useful.

  10. Common Notation Fig. 15.5

  11. Fig. 15.6

  12. Singleton Pattern • http://en.wikipedia.org/wiki/Singleton_pattern public class Singleton { // Private constructor suppresses // generation of a (public) default constructor private Singleton() {} private static class SingletonHolder { private static Singleton instance = new Singleton(); } public static Singleton getInstance() { return SingletonHolder.instance; } }

  13. Messages Fig. 15.7 also activation bar asynchronous with dashed lines

  14. Message Return Values: • Two ways to show the return result • Using the message syntax returnVar = message(parameter). • Using a reply (or return) message line at the end of an activation bar

  15. Fig. 15.8

  16. Fig. 15.9 representing a message sent to the same object; not just to an object of the same class this.clear()

  17. Fig. 15.10 New Object Creation dashed line because UML says so

  18. Fig. 15.11 I’m not sure where this fits in the Java paradigm?

  19. Fig. 15.12 [more items] I think this notation is starting to get out of hand. I, because I am drawing on the whiteboard, would draw and arrow like I have. In general, these are called diagram frames

  20. Fig. 15.13 I have no easy alternative to this; except to not bother trying to describe an entire algorithm.

  21. Diagram Frames: Frame Operator Meaning

  22. Fig. 15.14 I like this better

  23. Fig. 15.15

  24. Fig. 15.16

  25. Sample Code: public class Sale { private List<SalesLineItem> lineItems = new ArrayList<SalesLineItem>(); public Money getTotal() { Money total = new Money(); Money subtotal = null; for ( SalesLineItem lineItem : lineItems ) { subtotal = lineItem.getSubtotal(); total.add( subtotal ); } return total; } // … }

  26. Fig. 15.17 An alternative for Figure 15.16; nothing is official.

  27. Fig. 15.18 nested loops

  28. Fig. 15.19 sd == sequence diagram simplifies the first diagram

  29. Fig. 15.20

  30. Code Example: public class Foo { public void doX() { // static method call on class Calendar Locale[] locales = Calendar.getAvailableLocales(); // … } // … }

  31. Fig. 15.21 abstract method call individual implementations

  32. Fig. 15.22 asynchronous call Guideline This arrow difference is subtle. And when wall sketching UML, it is common to use a stick arrow to mean a synchronous call because it's easier to draw. Therefore, when reading a UML interaction diagram don't assume the shape of the arrow is correct!

  33. Code Example public class ClockStarter { public void startClock() { Thread t = new Thread( new Clock() ); t.start(); // asynchronous call to the 'run' method on the Clock System.runFinalization(); // example follow-on message } // … } // objects should implement the Runnable interface // in Java to be used on new threads public class Clock implements Runnable { public void run() { while ( true ) // loop forever on own thread { // … } } // … }

  34. Fig. 15.23

  35. Fig. 15.24

  36. Fig. 15.25

  37. Fig. 15.26

  38. Fig. 15.27

  39. Fig. 15.28

  40. Fig. 15.29

  41. Fig. 15.30

  42. Fig. 15.31

  43. Fig. 15.32

  44. Fig. 15.33

  45. Fig. 15.34

  46. Fig. 15.35

More Related