com s 362: object-oriented analysis and design interaction diagrams and responsibility assignment...

Post on 17-Jan-2018

217 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

DESCRIPTION

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

TRANSCRIPT

Com S 362: Object-Oriented Analysis and Design

Interaction Diagrams and

Responsibility Assignment Oct 23, 2006

2 Com S 362: Object-Oriented Analysis and Design2

Com S 362: Object-Oriented Analysis and Design

Recap: CRC Cards Process1. Initial class list2. Refined class list3. while (More use case scenarios left)4. do5. Take a use case scenario6. Assign responsibilities to classes7. Find super- and sub-classes8. Find collaborators9. od

3 Com S 362: Object-Oriented Analysis and Design3

Com S 362: Object-Oriented Analysis and Design

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 Design4

Com S 362: Object-Oriented Analysis and Design

Today’s Lecture Interaction Diagrams Basics & Notations Responsibility Assignment Principles

5 Com S 362: Object-Oriented Analysis and Design5

Com S 362: Object-Oriented Analysis and Design

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 Design6

Com S 362: Object-Oriented Analysis and Design

Class Diagram View

Switch

-state:bool

+getState():bool

Motor

-switch:Switch

+run()

1

switch

7 Com S 362: Object-Oriented Analysis and Design7

Com S 362: Object-Oriented Analysis and Design

Interaction Diagram View:Motor switch:Switch

rungetState

Lifeline boxes

state

8 Com S 362: Object-Oriented Analysis and Design8

Com S 362: Object-Oriented Analysis and Design

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: SwitchSubclasses: Super classes:

Responsibilities CollaboratorsStore decision condition

Class Name: MotorSubclasses:Super classes:

Responsibilities CollaboratorsMake a decision Switch

Run the motor

9 Com S 362: Object-Oriented Analysis and Design9

Com S 362: Object-Oriented Analysis and Design

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 Design10

Com S 362: Object-Oriented Analysis and Design

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 Design11

Com S 362: Object-Oriented Analysis and Design

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 Design12

Com S 362: Object-Oriented Analysis and Design

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 motorClass Name: SwitchSubclasses: Super classes:

Responsibilities CollaboratorsStore decision Condition

Make a decision

Class Name: MotorSubclasses:Super classes:

Responsibilities CollaboratorsRun the motor Switch

13 Com S 362: Object-Oriented Analysis and Design13

Com S 362: Object-Oriented Analysis and Design

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 Design14

Com S 362: Object-Oriented Analysis and Design

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 Design15

Com S 362: Object-Oriented Analysis and Design

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 Design16

Com S 362: Object-Oriented Analysis and Design

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: ProcessSubclasses: Super classes:

Responsibilities CollaboratorsStore information pc, .ps, .ds. regs

Class Name: Client …Subclasses:Super classes:

Responsibilities CollaboratorsCreate copy Processof .pc, .ps, .ds, .regs Spawn anotherprocess

17 Com S 362: Object-Oriented Analysis and Design17

Com S 362: Object-Oriented Analysis and Design

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: ProcessSubclasses: Super classes:

Responsibilities CollaboratorsStore information pc, .stack, .top, .ds. regs

Class Name: Client …Subclasses:Super classes:

Responsibilities CollaboratorsCreate copy Processof .pc, .ps, .ds, .regs Spawn anotherprocess

Impact on all clients

18 Com S 362: Object-Oriented Analysis and Design18

Com S 362: Object-Oriented Analysis and Design

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: ProcessSubclasses: Super classes:

Responsibilities CollaboratorsStore 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 Chang

e Impact Encap-sulate

d

19 Com S 362: Object-Oriented Analysis and Design19

Com S 362: Object-Oriented Analysis and Design

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: UISubclasses: Super classes:

Responsibilities CollaboratorsHandle Sort SortingAppEvent

Class Name: SortingAppSubclasses:Super classes:

Responsibilities CollaboratorsCreate sorting, ISort, IStoragestorage instance etc.

20 Com S 362: Object-Oriented Analysis and Design20

Com S 362: Object-Oriented Analysis and Design

Adding GUI to the Sorting Application

SortButton

/addActionListener(ActionListener l)

javax.swing.DefaultButtonModel

+addActionListener(ActionListener l)

SortingApplicationstorage:IStorage

sort:ISort

+sort(…):IStorage/actionPerformed(ActionEvent e)

java.awt.event.ActionListener

+actionPerformed(ActionEvent e)

21 Com S 362: Object-Oriented Analysis and Design21

Com S 362: Object-Oriented Analysis and Design

Summary Interaction Diagrams Responsibility Assignment Principles

Information Expert Creator Controller Polymorphism Pure Fabrication Indirection Protected Variations

22 Com S 362: Object-Oriented Analysis and Design22

Com S 362: Object-Oriented Analysis and Design

top related