Presentation is loading. Please wait.

Presentation is loading. Please wait.

Com S 362: Object-Oriented Analysis and Design Interaction Diagrams and Responsibility Assignment Oct 23, 2006.

Similar presentations


Presentation on theme: "Com S 362: Object-Oriented Analysis and Design Interaction Diagrams and Responsibility Assignment Oct 23, 2006."— Presentation transcript:

1 Com S 362: Object-Oriented Analysis and Design Interaction Diagrams and Responsibility Assignment Oct 23, 2006

2 Com S 362: Object-Oriented Analysis and Design 2 2 Recap: CRC Cards Process 1. Initial class list 2. Refined class list 3. while (More use case scenarios left) 4. do 5. Take a use case scenario 6. Assign responsibilities to classes 7. Find super- and sub-classes 8. Find collaborators 9. od

3 Com S 362: Object-Oriented Analysis and Design 3 3 Recap: Class Diagrams Class diagrams represent design structure Three parts: name, attribute, operations Visibility, attribute type, multiplicity Association, association multiplicity Generalization i.e. interface impl, subclassing Composition i.e. class A contains class B Applied information hiding, DSM, layering

4 Com S 362: Object-Oriented Analysis and Design 4 4 Today’s Lecture Interaction Diagrams Basics & Notations Responsibility Assignment Principles

5 Com S 362: Object-Oriented Analysis and Design 5 5 Example: Switch-Motor System Scenario: Motor can run, when the Switch state is on Class list: Switch and Motor R1: Store the decision condition R2: Make a decision R3: Run the motor

6 Com S 362: Object-Oriented Analysis and Design 6 6 Class Diagram View Switch -state:bool +getState():bool Motor -switch:Switch +run() 1 switch

7 Com S 362: Object-Oriented Analysis and Design 7 7 Interaction Diagram View :Motorswitch:Switch run getState Lifeline boxes state

8 Com S 362: Object-Oriented Analysis and Design 8 8 Switch-Motor: CRC Card View Scenario: Motor can run, when the Switch state is on Class list: Switch and Motor R1: Store the decision condition, R2: Make a decision, and R3: Run the motor Class Name: Switch Subclasses: Super classes: Responsibilities Collaborators Store decision condition Class Name: Motor Subclasses: Super classes: Responsibilities Collaborators Make a decision Switch Run the motor

9 Com S 362: Object-Oriented Analysis and Design 9 9 Class Diagram View Switch -state:bool +getState():bool Motor -switch:Switch +run():void 1 switch void run(){ if(switch.getState()){ /* Make a decision */ /* run the motor */ }

10 Com S 362: Object-Oriented Analysis and Design 10 Com S 362: Object-Oriented Analysis and Design 10 Impact of Change: Multi-State Switch Switch -state:bool +getState():bool Motor -switch:Switch +run():void 1 switch void run(){ if(switch.getState()){ /* Make a decision */ /* run the motor */ } -state:int +getState():int Change: Switch can have more than two states.

11 Com S 362: Object-Oriented Analysis and Design 11 Com S 362: Object-Oriented Analysis and Design 11 Change Escapes Module Boundary Switch -state:bool +getState():bool Motor -switch:Switch +run():void 1 switch void run(){ if(switch.getState()){ /* Make a decision */ /* run the motor */ } Change: Switch can have more than two states. -state:int +getState():int Impact of Change

12 Com S 362: Object-Oriented Analysis and Design 12 Com S 362: Object-Oriented Analysis and Design 12 Information Expert Which class has the necessary information? Example – class list: Switch and Motor R1: Store the decision condition, R2: Make a decision, and R3: Run the motor Class Name: Switch Subclasses: Super classes: Responsibilities Collaborators Store decision Condition Make a decision Class Name: Motor Subclasses: Super classes: Responsibilities Collaborators Run the motor Switch

13 Com S 362: Object-Oriented Analysis and Design 13 Com S 362: Object-Oriented Analysis and Design 13 Improved Class Diagram View Switch -state:bool +isOn():bool Motor -switch:Switch +run():void 1 switch void run(){ if(switch.isOn()){ /* run the motor */ }

14 Com S 362: Object-Oriented Analysis and Design 14 Com S 362: Object-Oriented Analysis and Design 14 Implementation Changes Encapsulated Switch -state:bool +isOn():bool Motor -switch:Switch +run():void 1 switch void run(){ if(switch.isOn()){ /* run the motor */ } Change: Switch can have more than two states. -state:int +isOn():bool Remember: Information Hiding

15 Com S 362: Object-Oriented Analysis and Design 15 Com S 362: Object-Oriented Analysis and Design 15 Example: User-Level Process Management Main scenario: A process will maintain necessary information for it to run such as program counter (PC), reference to program segment (.ps), reference to data segments (.ds), registers (regs) Scenario of interest: functionality to create an identical copy of a process should be provided Class list: process, client R1: store information PC,.ps,.ds. Regs R2: create copy of process

16 Com S 362: Object-Oriented Analysis and Design 16 Com S 362: Object-Oriented Analysis and Design 16 User-Level Process Management : CRC Card View Class list: process, client R1: store information pc,.ps,.ds. regs R2: create copy of process Class Name: Process Subclasses: Super classes: Responsibilities Collaborators Store information pc,.ps,.ds. regs Class Name: Client … Subclasses: Super classes: Responsibilities Collaborators Create copy Process of.pc,.ps,.ds,.regs Spawn another process

17 Com S 362: Object-Oriented Analysis and Design 17 Com S 362: Object-Oriented Analysis and Design 17 Change: Register-based to Stack-based Machine Class list: process, client R1: store information pc,.stack,.top,.ps,.ds. R2: create copy of process Class Name: Process Subclasses: Super classes: Responsibilities Collaborators Store information pc,.stack,.top,.ds. regs Class Name: Client … Subclasses: Super classes: Responsibilities Collaborators Create copy Process of.pc,.ps,.ds,.regs Spawn another process Impact on all clients

18 Com S 362: Object-Oriented Analysis and Design 18 Com S 362: Object-Oriented Analysis and Design 18 Creator: Which class has the initializing data? Class list: process, client R1: store information pc,.ps,.ds. regs R2: create copy of process Class Name: Process Subclasses: Super classes: Responsibilities Collaborators Store information pc,.ps,.ds. regs Create copy of.pc,.ps,.ds,. regs and spawn another process Class Name: Client … Subclasses: Super classes: Responsibilities Collaborators Process Change Impact Encap- sulated

19 Com S 362: Object-Oriented Analysis and Design 19 Com S 362: Object-Oriented Analysis and Design 19 Adding GUI to the Sorting Application Integers (>0) Sorting Algorithm Sorting Application Merge Sort Sort : User Which class should handle the Sort Event? Class Name: UI Subclasses: Super classes: Responsibilities Collaborators Handle Sort SortingApp Event Class Name: SortingApp Subclasses: Super classes: Responsibilities Collaborators Create sorting, ISort, IStorage storage instance etc.

20 Com S 362: Object-Oriented Analysis and Design 20 Com S 362: Object-Oriented Analysis and Design 20 Adding GUI to the Sorting Application SortButton … /addActionListener(ActionListener l) javax.swing.DefaultButtonModel … +addActionListener(ActionListener l) SortingApplication storage:IStorage sort:ISort +sort(…):IStorage /actionPerformed(ActionEvent e) java.awt.event.ActionListener … +actionPerformed(ActionEvent e)

21 Com S 362: Object-Oriented Analysis and Design 21 Com S 362: Object-Oriented Analysis and Design 21 Summary Interaction Diagrams Responsibility Assignment Principles Information Expert Creator Controller Polymorphism Pure Fabrication Indirection Protected Variations

22 Com S 362: Object-Oriented Analysis and Design 22 Com S 362: Object-Oriented Analysis and Design 22


Download ppt "Com S 362: Object-Oriented Analysis and Design Interaction Diagrams and Responsibility Assignment Oct 23, 2006."

Similar presentations


Ads by Google