Download presentation
1
Starting Object Design
Chapter 14 Starting Object Design
2
Spend time on dynamic models They are the key tool for building good static models
3
One Object Design Technique: Class Responsibility Collaboration (CRC) cards
4
CRC Card examples
5
Dynamic modeling of object: Interaction Diagrams
Chapter 15 Dynamic modeling of object: Interaction Diagrams
6
UML Interaction Diagrams
Two variants Sequence diagrams Communication diagrams
7
Example: Sequence Diagram
8
What does this represent in code?
public class A { private B myB = new B(); public void doOne() { myB.doTwo(); myB.doThree(); }
9
Example: Collaboration Diagram
10
Strengths and Weaknesses of Sequence and Collaboration Diagrams
11
Example Sequence Diagram
public class Sale { private Payment payment; public void makePayment(Money cashTendered) { payment = new Payment(cashTendered); // ... }
12
Example collaboration diagram
public class Sale { private Payment payment; public void makePayment(Money cashTendered) { payment = new Payment(cashTendered); // ... }
13
Lifeline boxes
14
Used if we want only ONE instance of a class instantiated
The Singleton Pattern Used if we want only ONE instance of a class instantiated Examples: Database, log We’ll learn how to accomplish this in Java later
15
Lifelines, messages, “found” or “starting” messages
16
Illustrating Replies or Return Values
Two alternatives Using the message syntax returnVar = message(parameter) Use a reply or return message at the end of an activation bar
17
Messages to “self” or “this”
18
Instance Creation
19
Object Destruction (Object no longer used or usable)
Object explicitly destroyed or no longer usable (reachable) Example: No variable refers to object any longer Marked for garbage collection
20
Looping notation
21
A conditional message
22
UML Version 1 notation for conditional messages
23
Mutually exclusive conditional messages
24
Iteration over a collection: Explicit notation
Selector expression
25
Iteration over a collection: Implicit notation
26
Nested frames
27
How to relate interaction diagrams (hierarchical notation)
28
Invoking static or class methods
public class Foo { public void doX() { // Static method call on class Calendar Locale[] locales = Calendar.getAvailableLocales() // ... }
29
Polymorphic Messages and Cases
30
Polymorphic Messages and Cases
31
Asynchronous vs. Synchronous Calls
Asynchronous message: Does not wait for a response “It doesn’t block” Used in multi-threaded environments New threads can be created and initiated Example: In Java Thread.start Runnable.run initiate execution of a new thread
32
Asynchronous vs. Synchronous Calls
Active object: Each instance runs on and controls its own thread of execution Example: Clock
33
Collaboration Diagram Notation
Link: Connection path between two objects Indicates a form of navigation or visibility between the objects Formally: An instance of an association There can be only one link between two objects Multiple messages in both directions flow along this link
34
Communication Diagram Notation
35
Messages to “self” or “this”
36
Instance creation in communication diagrams
37
Sequence Numbering Nested message
38
Sequence Numbering
39
Sequence Numbering
40
Conditional messages
41
Mutually exclusive conditional messages
42
Iteration in communication diagrams
43
Iteration over a collection
44
Static method invocation (message to a class)
45
Modeling polymorphic cases in communication diagrams
46
Asynchronous messages in communication diagrams
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.