object oriented analysis and design using the uml version 4 · ooad using the uml - class design, v...

131
OOAD Using the UML - Class Design, v 4.2 Copyright © 1998-1999 Rational Software, all rights reserved 1 Object Oriented Analysis and Design Using the UML Version 4.2 Module 13: Class Design

Upload: dangkiet

Post on 08-May-2018

244 views

Category:

Documents


3 download

TRANSCRIPT

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 1

Object Oriented Analysis and DesignUsing the UML

Version 4.2

Module 13: Class Design

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 2

Objectives: Class Design

Understand the purpose of Class Designand where in the lifecycle it is performed

Identify additional classes and relationshipsneeded to support implementation of thechosen architectural mechanisms

Identify and analyze state transitions inobjects of state-controlled classes

Refine relationships, operations, andattributes

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 3

Class Design in Context

Architect

Designer

ArchitecturalAnalysis

ArchitectureReviewer

Review theDesign

Review theArchitecture

Use-CaseAnalysis

ArchitecturalDesign

DescribeConcurrency

DescribeDistribution

ClassDesign

Subsystem Design

Use-Case Design

DesignReviewer

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 4

Class Design Overview

SupplementarySpecifications

ClassDesign

Architecture Document

Design Model

DesignGuidelines

Use-Case Realization

Design Classes

Design Classes

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 5

Class Design Steps

Create Initial Design Classes Identify Persistent Classes Define Operations Define Class Visibility Define Methods Define States Define Attributes Define Dependencies Define Associations Define Generalizations Resolve Use-Case Collisions Handle Non-Functional Requirements in General Checkpoints

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 6

Class Design Steps

Create Initial Design Classes Identify Persistent Classes Define Operations Define Class Visibility Define Methods Define States Define Attributes Define Dependencies Define Associations Define Generalizations Resolve Use-Case Collisions Handle Non-Functional Requirements in General Checkpoints

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 7

Class Design Considerations

Class stereotype Boundary Entity Control

Applicable design patterns Architectural mechanisms

Persistence Distribution etc.

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 8

A class should have a single well focused purpose.A class should do one thing and do it well!

How Many Classes Are Needed?

Many, simple classes means that each class Encapsulates less of the overall system

intelligence Is more reusable Is easier to implement

A few, complex classes means that each class Encapsulates a large portion of the overall

system intelligence Is less likely to be reusable Is more difficult to implement

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 9

MainForm

SubWindow

DropDownListButton

MainWindow

Designing Boundary Classes

User interface (UI) boundary classes What user interface development tools will be

used? How much of the interface can be created by

the development tool? External system interface boundary classes

Usually model as subsystem

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 10

Analysis DesignFatClass

- transientBookeeping

+ getCommonlyUsedAtt1()+ getCommonlyUsedAtt2()+ getRarelyUsedAtt3()+ getRarelyUsedAtt4()

FatClassDataHelper+ commonlyUsedAtt1+ commonlyUsedAtt2

FatClassLazyDataHelper+ rarelyUsedAtt3+ rarelyUsedAtt4

1 1

FatClass- transientBookeeping+ commonlyUsedAtt1+ commonlyUsedAtt2+ rarelyUsedAtt3+ rarelyUsedAtt4

<< entity >>

Designing Entity Classes

Entity objects are often passive and persistent Performance requirements may force some re-

factoring See Identify Persistent Classes step

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 11

Designing Control Classes

What Happens to Control Classes? Are they really needed? Should they be split?

How do you decide? Complexity Change probability Distribution and performance Transaction management

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 12

Class Design Steps

Create Initial Design Classes Identify Persistent Classes Define Operations Define Class Visibility Define Methods Define States Define Attributes Define Dependencies Define Associations Define Generalizations Resolve Use-Case Collisions Handle Non-Functional Requirements in General Checkpoints

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 13

Any instance of the class requires its state to bepreserved

Persistent classes are mapped to the persistencemechanism

Persistence strategy must be coordinatedClientClass

Persistency

AnalysisMechanism

(Conceptual)

DesignMechanism(Concrete)

ImplementationMechanism

(Actual)

OODBMS

RDBMS JDBC to Ingres

ObjectStore

Legacy Data

New Data

Course

StudentPersistency

Identify Persistent Classes

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 14

ClassDesign

DatabaseDesign

Class

Database DesignerData Model

Designer

Database Design Preview

Persistence strategy must be coordinated At this point, just indicate the classes are

persistent

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 15

Class Design Steps

Create Initial Design Classes Identify Persistent Classes Define Operations Define Class Visibility Define Methods Define States Define Attributes Define Dependencies Define Associations Define Generalizations Resolve Use-Case Collisions Handle Non-Functional Requirements in General Checkpoints

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 16

Define Operations

Purpose Map responsibilities defined in analysis to the

operations that implement them Things to consider :

Operation name, signature, and description Operation visibility Operation scope

• Class operation vs. instance operation

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 17

Review: What is an Operation?

CourseOffering

addStudentdeleteStudentgetStartTimegetEndTime

Class

Operation

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 18

:ClassA

// Perform responsibility

:ClassB :ClassA

performResponsibility():result

:ClassB

Operations: Where Do You Find Them?

Messages displayed in interaction diagrams

Other implementation dependentfunctionality Manager functions Need for class copies Need to test for equality

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 19

Name and Describe the Operations

Appropriate operation names Indicate the outcome Use client perspective Consistent across classes

Define operation signatures operationName(parameter : class,..) :

returnType Provide short description, including

meaning of all parameters

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 20

Guidelines: Designing Operation Signatures

When designing operation signatures besure to include: Parameters passed by-value or by-reference? Parameters changed by operation? Parameters optional? Default parameter values? Valid parameter ranges?

The fewer the parameters, the better Pass objects instead of “data bits”

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 21

Discovering Additional Classes and Relationships

Additional classes and relationships may beadded to support signature

ClassA Class2

op1(var1:Class2): Class3

Class3

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 22

Publicoperations

Protectedoperations

Private operations

Operation Visibility

Visibility is used to enforce encapsulation May be public, protected, or private

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 23

Class- privateAttribute# protectedAttribute

+publicOp()# protectedOp()- privateOp()

How Is Visibility Noted?

The following symbols are used to specifyexport control: + Public access # Protected access - Private access

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 24

Class

- classifierScopeAttribute

classifierScopeOperation()

- instanceScopeAttribute

instanceScopeOperation()

Scope

Determines number of instances of theattribute/operation Instance: one instance for each class instance Classifier: one instance for all class instances

Classifier scope is denoted by underliningthe attribute/operation name

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 25

Example: Scope

Student- name- address

- nextAvailID : int

+ addSchedule(theSchedule : Schedule, forSemester : Semester)+ getSchedule(forSemester : Semester) : Schedule+ hasPrerequisites(forCourseOffering : CourseOffering) : boolean# passed(theCourseOffering : CourseOffering) : boolean+ getNextAvailID() : int

<<entity>>

- studentID

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 26

MathFunctions<<utility>>

Utility Classes

What is a Utility Class? Utility is a class stereotype Used for a class that contains a collection of

free subprograms Why use it?

To provide services that may be (re)useful in avariety of contexts

To wrap non object-oriented libraries orapplications

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 27

Example: Utility Classes

<<utility>> MathPack

-randomSeed : long = 0randomSeed : long = 0--pi : double = 3.14159265358979pi : double = 3.14159265358979

+sin (angle : double) : double+cos (angle : double) : double+random() : double

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 28

Example: Define Operations

CourseOffering(from University Artifacts)

<<entity>>

Student.

+ getTuition() : double+ addSchedule(theSchedule : Schedule)+ getSchedule(forSemester : Semester) : Schedule+ deleteSchedule(forSemester : Semester)+ hasPrerequisites(forCourseOffering : CourseOffering) : boolean# passed(theCourseOffering : CourseOffering) : boolean<<class>> + getNextAvailID() : int+ getStudentID() : int+ getName() : string+ getAddress() : string

(from University Artifacts)

<<entity>>

RegistrationController

+ submitSchedule()+ saveSchedule()+ getCourseOfferings() : CourseOfferingList+ getCurrentSchedule(forStudent : Student, forSemester : Semester) : Schedule+ deleteCurrentSchedule()<<class>> + new(forStudent : string)+ getStudent(withID : string) : Student

(from Registration)

<<control>>

Schedule(from University Artifacts)

<<entity>>

0..1

0..1+registrant

0..*

1

0..10..1

+currentSchedule

0..*

0..*

+primaryCourses

0..4

+alternateCourses

0..2

ICourseCatalogSystem

+ getCourseOfferings()+ initialize()

(from External System Interfaces)

<<Interface>>

10..*

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 29

(continued)

Exercise: Define Operations

Given the following: The architectural layers, their packages, and

their dependencies Design classes for a particular use case

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 30

(continued)

Exercise: Define Operations (cont.)

Identify the following for the design classes: Operations and complete operation signatures Operation scope and visibility Any additional relationships and/or classes to

support the defined operations and operationsignatures

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 31

Exercise: Define Operations (cont.)

Produce the following diagrams: VOPC class diagram, containing all operations,

operation signatures, and relationships

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 32

Class Design Steps

Create Initial Design Classes Identify Persistent Classes Define Operations Define Class Visibility Define Methods Define States Define Attributes Define Dependencies Define Associations Define Generalizations Resolve Use-Case Collisions Handle Non-Functional Requirements in General Checkpoints

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 33

Review: Package Element VisibilityPackageA

Class A1

Class A3

Class A2A

BPackageB

+Class B1-Class B2Public visibility

Private visibility

Only public classescan be referenced

outside of theowning package

OO Principle: Encapsulation

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 34

Class Design Steps

Create Initial Design Classes Identify Persistent Classes Define Operations Define Class Visibility Define Methods Define States Define Attributes Define Dependencies Define Associations Define Generalizations Resolve Use-Case Collisions Handle Non-Functional Requirements in General Checkpoints

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 35

Define Methods

What is a method? Describes operation implementation

Purpose Define special aspects of operation

implementation Things to consider :

Special algorithms Other objects and operations to be used How attributes and parameters are to be

implemented and used How relationships are to be implemented and

used

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 36

Class Design Steps

Create Initial Design Classes Identify Persistent Classes Define Operations Define Class Visibility Define Methods Define States Define Attributes Define Dependencies Define Associations Define Generalizations Resolve Use-Case Collisions Handle Non-Functional Requirements in General Checkpoints

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 37

Define States

Purpose Design how an object’s state affects its

behavior Develop statecharts to model this behavior

Things to consider : Which objects have significant state? How to determine an object’s possible states? How do statecharts map to the rest of the

model?

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 38

State Name

stateVar : type = value

entry/ entry actiondo/ activityexit/ exit action

event(args) [guard condition] / operation(args) ^target.sendEvent(args)

State Event

Transition

Action

Activity

What is a Statechart?

A directed graph of states (nodes)connected by transitions(directed arcs)

Describes the life history of a reactiveobject

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 39

Initial state The state entered when an object is created Mandatory Can only have one initial state

Final state Indicates the object’s end of life Optional May have more than one

Final state

Initial state

Special States

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 40

Process For Deriving Statecharts

Identify and define the states Identify the events Identify the transitions (i.e., the event

responses) Add activities and actions

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 41

numStudents < 10

Open

The maximum number of students per course offering is 10

numStudents > = 10

Closed

Assigned Unassigned

Link to ProfessorExists

Link to ProfessorDoesn’t Exist

Professor

CourseOffering

0..*

0..1

Identify and Define the States

Significant, dynamic attributes

Existence and non-existence of certain links

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 42

+instructor

CourseOffering+ addProfessor()+ removeProfessor()

<<entity>>

Professor<<entity>>0..10..*

Events: addProfessor, removeProfessor

Identify the Events

Look at the class interface operations

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 43

Unassigned

Assigned

removeProfessor

addProfessor

+instructorCourseOffering

+ addProfessor()+ removeProfessor()

<<entity>>

Professor<<entity>>0..10..*

Identify the Transitions

For each state, determine what events causetransitions to what states, including guard conditions,when needed

Transitions describe what happens in response to thereceipt of an event

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 44

State A

State Bdo: activity

event[ condition ] / action

State Cactivity

action

entry: action

Add Activities and Actions

Activities Associated with a state Start when the state is entered Take time to complete Interruptible

Actions Associated with a transition Take an insignificant amount of time to

complete Non-interruptible

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 45

Send Events

One event may trigger the sending ofanother event

An activity can also send an event toanother object

State Bdo: ^TargetObject.event

State A

event ^TargetObject.event

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 46

Example: Statechartadd student / numStudents = numStudents + 1

Unassigned

Assigned

Full

Cancelleddo: Send cancellation notices

Committeddo: Generate class roster

closeRegistration [ has Professor assigned ]

close

/ numStudents = 0

addProfessor

closeRegistration

remove student / numStudents = numStudents - 1

cancel

removeProfessor

[ numStudents = 10 ]

close[ numStudents < 3 ]

closeRegistration[ numStudents >= 3 ]

close[ numStudents >= 3 ]

add student /numStudents = numStudents + 1

cancel

remove student / numStudents = numStudents - 1

close

[ numStudents = 10 ] cancel

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 47

Example: Statechart With Nested States and Historysuperstate

substate

add student /numStudents = numStudents + 1

Open

Unassigned

Assigned

H

add a professor

Closed

Cancelleddo: Send cancellation notices

Full

Committeddo: Generate class roster

closeRegistration

close

remove a professorclose[ numStudents < 3 ]

[ numStudents = 10 ]

closeRegistration[ numStudents >= 3 ]

close[ numStudents >= 3 ]

closeRegistration [ has Professor assigned ]

close

/ numStudents = 0

remove student / numStudents = numStudents - 1

cancelcancel

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 48

Which Objects Have Significant State?

Objects whose role is clarified by statetransitions

Complex use cases that are state-controlled It is not necessary to model all objects

Objects with straightforward mapping toimplementation

Objects that are not state-controlled Objects with only one computational state

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 49

Open Full

add student /numStudents = numStudents + 1

[numStudents = 10]

CourseOffering

/- numStudents

+ addStudent()(Stay tuned for derived attributes)

How Do Statecharts Map to the Rest of the Model?

Events may map to operations Methods should be updated with state-

specific information States are often represented using

attributes This serves as input into the Define Attributes

step

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 50

Exercise: Define States (optional)

Given the following: All design classes

Identify the following: Class(es) with significant state-controlled

behavior The important states and transitions for the

identified class Produce the following diagrams:

Statechart for one of the classes that exhibitsstate-controlled behavior

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 51

Class Design Steps

Create Initial Design Classes Identify Persistent Classes Define Operations Define Class Visibility Define Methods Define States Define Attributes Define Dependencies Define Associations Define Generalizations Resolve Use-Case Collisions Handle Non-Functional Requirements in General Checkpoints

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 52

Define Attributes

Purpose Formalize definition of attributes

Things to consider: Persistency Visibility Name, type, and initial default value

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 53

Review: What is an Attribute?

:CourseOfferingnumber = 101startTime = 900endTime = 1100

:CourseOfferingnumber = 104startTime = 1300endTime = 1500

CourseOfferingnumberstartTimeendTime

Class

Attribute

Object

Attribute Value

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 54

Attributes: How Do You Find Them?

Examine method descriptions Examine states Any information the class itself needs to

maintain

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 55

Attribute Representations

Specify name, type, and optional default value attributeName : Type = Default

Follow naming conventions of implementationlanguage and project

Type should be an elementary data type inimplementation language Built-in data type, user-defined data type, or

user-defined class Specify visibility

Public: ‘+’ Private: ‘-’ Protected: ‘#’

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 56

Derived Attributes

What is a derived attribute? An attribute whose value may be calculated

based on the value of other attribute(s) When do you use them?

When there is not enough time to re-calculatethe value every time it is needed

Trade-off runtime performance vs. memoryrequired

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 57

Example: Define Attributes

Student.

- name : string- address : string<<class>> - nextAvailID : int- studentID : int- dateofBirth : Date

(from University Artifacts)

<<entity>>

RegistrationController(from Registration)

<<control>>

Schedule

- semester : Semester(from University Artifacts)

<<entity>>

CourseOffering

- number : String = "100"- startTime : Time- endTime : Time- days : string/- numStudents : int = 0

(from University Artifacts)

<<entity>>

ICourseCatalogSystem(from External System Interfaces)

<<Interface>>

0..1

0..1

+registrant0..*

1

0..1

0..1

+currentSchedule

0..*

0..*

+primaryCourses

0..4

+alternateCourses

0..2

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 58

(continued)

Exercise: Define Attributes (optional)

Given the following: The architectural layers, their packages, and

their dependencies Design classes for a particular use case

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 59

(continued)

Exercise: Define Attributes (cont.)

Identify the following for the design class: Attributes and complete attribute signatures Attribute scope and visibility Any additional relationships and/or classes to

support the defined attributes and attributesignatures

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 60

Exercise: Define Attributes (cont.)

Produce the following diagrams: VOPC class diagram, containing all attributes

and relationships

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 61

Class Design Steps

Create Initial Design Classes Identify Persistent Classes Define Operations Define Class Visibility Define Methods Define States Define Attributes Define Dependencies Define Associations Define Generalizations Resolve Use-Case Collisions Handle Non-Functional Requirements in General Checkpoints

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 62

What Is a Dependency? A relationship between two objects

Purpose Determine where structural relationships are

NOT required Things to look for :

What causes the supplier to be visible to theclient

Client Supplier

Define Dependency

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 63

Associations are structural relationships Dependencies are non-structural

relationships In order for objects to “talk” they must be

visible Local variable reference Parameter reference Global reference Field reference Association

Client

Supplier1

Supplier2

Dependency

Dependencies vs. Associations

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 64

ClassA

op1 ()

ClassB

Local Variable Visibility

The op1() operation contains a localvariable of type ClassB

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 65

ClassA

op1 (param1: ClassB)

ClassB

Parameter Visibility

The ClassB instance is passed to theClassA instance

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 66

ClassUtility

utilityOp ()

ClassA

op1 ()

Global Visibility

The ClassUtility instance is visible becauseit is global

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 67

Strive for real-world relationships Strive for the lightest relationships possible (dependency) Is relationship “permanent”? Use association (field

visibility) Is relationship “temporary”? Use dependency

Multiple objects share the same instance• Pass instance as a parameter (parameter visibility)• Make instance a managed global (global visibility)

Multiple objects don’t share the same instance (localvisibility)

How long does it take to create/destroy? Expensive? Use field, parameter, or global visibility

Which choice is right? IT DEPENDS

Identifying Dependencies: Considerations

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 68

Example: Define Dependencies (before)

ICourseCatalogSystem

+ getCourseOfferings(forSemester : Semester) : CourseOfferingList

(from External System Interfaces)

<<Interface>>

Student

- name- address- StudentID : int

+ addSchedule(theSchedule : Schedule, forSemester : Semester)+ getSchedule(forSemester : Semester) : Schedule+ hasPrerequisites(forCourseOffering : CourseOffering) : boolean# passed(theCourseOffering : CourseOffering) : boolean

(from University Artifacts)

<<entity>>

RegistrationController

+ // submit schedule()+ // save schedule()+ // create schedule with offerings()+ // getCourseOfferings(forSemester) : CourseOfferingList

(from Registration)

<<control>>

0..1

0..1registrant

0..*1

courseCatalog

Schedule

- semester

+ submit()+ // save()# any conflicts?()+ // create with offerings()

(from University Artifacts)

<<entity>>

0..*

1

0..1 0..1

currentSchedule

CourseOffering

- number : String = "100"- startTime : Time- endTime : Time- days : Enum

+ addStudent(studentSchedule : Schedule)+ removeStudent(studentSchedule : Schedule)+ new()+ setData()

(from University Artifacts)

<<entity>>

0..*

0..4

primaryCourses0..*

0..2alternateCourses

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 69

Example: Define Dependencies (after)

Global visibility

Parameter visibility

ICourseCatalogSystem

+ getCourseOfferings(forSemester : Semester) : CourseOfferingList

(from External System Interfaces)

<<Interface>>

Student

- name- address- StudentID : int

+ addSchedule(theSchedule : Schedule, forSemester : Semester)+ getSchedule(forSemester : Semester) : Schedule+ hasPrerequisites(forCourseOffering : CourseOffering) : boolean# passed(theCourseOffering : CourseOffering) : boolean

(from University Artifacts)

<<entity>>

RegistrationController

+ // submit schedule()+ // save schedule()+ // create schedule with offerings()+ // getCourseOfferings(forSemester) : CourseOfferingList

(from Registration)

<<control>>

0..1

0..1registrant

Schedule

- semester

+ submit()+ // save()# any conflicts?()+ // create with offerings()

(from University Artifacts)

<<entity>>

0..*

1

0..1 0..1

currentSchedule

CourseOffering

- number : String = "100"- startTime : Time- endTime : Time- days : Enum

+ addStudent(studentSchedule : Schedule)+ removeStudent(studentSchedule : Schedule)+ new()+ setData()

(from University Artifacts)

<<entity>>

0..*

0..4

primaryCourses0..*

0..2alternateCoursesField visibility

Field visibility

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 70

Class Design Steps

Create Initial Design Classes Identify Persistent Classes Define Operations Define Class Visibility Define Methods Define States Define Attributes Define Dependencies Define Associations Define Generalizations Resolve Use-Case Collisions Handle Non-Functional Requirements in General Checkpoints

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 71

Define Associations

Purpose Refine remaining associations

Things to look for : Association vs. Aggregation Aggregation vs. Composition Attribute vs. Composition Navigability Association class design Multiplicity design

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 72

Whole Part

Whole

Aggregation

Part

Review: What is Composition?

A form of aggregation with strongownership and coincident lifetimes The parts cannot survive the whole/aggregate

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 73

1

Whole Part1..* 0..*

Multiplicity > 1

Whole Part1 0..*

Multiplicity = 1

By definition, composition is non-shared aggregation

Whole Part0..*

Multiplicity = 1

Composition

Aggregation: Shared Vs. Non-shared

Shared Aggregation

Non-shared Aggregation

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 74

aggregation

composition

Class1

Class1

Class2

Class2

Aggregation or Composition?

Consideration Lifetimes of Class1 and Class2

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 75

Example: Composition

Student Schedule1 0..*

RegisterForCoursesForm 1 1 RegistrationController

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 76

Attributes Vs Composition

Use composition when Properties need independent identities Multiple classes have the same properties Properties have a complex structure and

properties of their own Properties have complex behavior of their own Properties have relationships of their own

Otherwise use attributes

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 77

Example: Attributes Vs Composition

Compositionof separateclass

Attributes

0..*11

Student- name- address<<classifier scope>> - nextAvailID : int- StudentID : int- dateofBirth : Date

+ addSchedule()+ getSchedule()+ delete schedule()+ hasPrerequisites()# passed()

<<entity>>

Schedule

+ submit()+ // save()# any conflicts?()+ // create with offerings()+ new()+ passed()

<<entity>>

- Semester

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 78

?

Schedule CourseOffering

0..40..*

primaryCourses

Schedule CourseOffering

0..40..*

primaryCourses Schedule CourseOffering

0..40..*

primaryCourses

Navigability: Which Directions Are Really Needed?

Explore interaction diagrams Even when both directions seem required,

one may work Navigability in one direction is infrequent Number of instances of one class is small

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 79

Example: Navigability Refinement

Total number of Schedulesis small, or

Never need a list of theSchedules on which theCourseOffering appears

Total number ofCourseOfferings is small, or

Never need a list ofCourseOfferings on aSchedule

Total number ofCourseOfferings andSchedules are not small

Must be able to navigate inboth directions

Schedule CourseOffering

0..40..*

primaryCourses

Schedule CourseOffering

0..40..*

primaryCourses

Schedule CourseOffering

0..40..*

primaryCourses

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 80

Example: Association Class Design

Schedule CourseOffering

0..40..*

primaryCourses

PrimaryScheduleOfferingInfo- grade: char = I

alternateCourses

0..20..*

0..*

Schedule CourseOffering11 0..4

0..20..*alternateCourses

primaryCourseOfferingInfo PrimaryScheduleOfferingInfo- grade: char = I

Design Decisions

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 81

Multiplicity = 1, or Multiplicity = 0..1 May be implemented directly as simple value

or pointer No further “design” required

Multiplicity > 0 Cannot use a simple value or pointer Further “design” may be required

Professor CourseOffering

0..*0..1

Professor CourseOffering

0..*0..1

instructor

instructor

Multiplicity Design

Needs acontainer

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 82

Multiplicity Design Options

Explicit modeling of a container class

Note

instructorProfessor CourseOffering

0..*0..1

CourseOffering<<entity>>

Professor<<entity>>

CourseOfferingList

+ new()+ add()

1

0..*

0..10..1

+instructor

Professor CourseOffering

0..*0..1

instructor

List

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 83

Item

ListParameterizedClass

Formalarguments

What is a Parameterized Class (template)?

A class definition which defines otherclasses

Often used for container classes Some common container classes:

• Sets, lists, dictionaries, stacks, queues, …

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 84

Instantiating a Parameterized Class

Instantiated Class <actual arguments>

<<bind>> <actual arguments>

ParameterizedClass

Formalarguments

Instantiated Class

OR

Implicit bindingExplicit binding

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 85

Example: Instantiating a Parameterized Class

CourseOffering<<entity>>CourseOfferingList

1 0..*

Before

After

<<bind>> <CourseOffering>

List

Item

CourseOfferingList CourseOffering

List <CourseOffering> CourseOfferingOR

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 86

CourseOfferingProfessor

isTeaching( ) : Boolean 0..1 0..* hasInstructor( ) : Boolean

Multiplicity Design: Optionality

If a link is optional, make sure to include anoperation to test for the existence of the link

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 87

(continued)

Exercise: Define Dependencies and Associations

Given the following: The use-case realization for a use case and/or

the detailed design of a subsystem The design of all participating design elements

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 88

(continued)

Exercise: Define Dependencies and Associations (cont.)

Identify the following: The required navigability for each relationship Any additional classes to support the

relationship design Any associations refined into dependencies Any associations refined into aggregations or

compositions Any refinements to multiplicity

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 89

Exercise: Define Dependencies and Associations (cont.)

Produce the following diagrams An updated VOPC, including the relationship

refinements

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 90

Class Design Steps

Create Initial Design Classes Identify Persistent Classes Define Operations Define Class Visibility Define Methods Define States Define Attributes Define Dependencies Define Associations Define Generalizations Resolve Use-Case Collisions Handle Non-Functional Requirements in General Checkpoints

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 91

Define Generalizations

Purpose Identify areas of reuse Refine existing inheritance hierarchies so that they

can be implemented efficiently Things to look for:

Abstract classes vs. concrete classes Multiple inheritance problems Generalization vs. Aggregation Generalization to support implementation reuse Generalization to support polymorphism Generalization to support metamorphosis Generalization simulation

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 92

Review: Generalization

One class shares the structure and/orbehavior of one or more classes

“Is-a-kind of” relationship In analysis, use sparingly

Accountbalancenamenumber

Withdraw()CreateStatement()

Checking Savings

GetInterest()

Superclass(parent)

Subclasses

GeneralizationRelationship

descendents

ancestor

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 93

Lion

talk ()

Elephant

talk ()

Animal{abstract}

talk () {abstract}

There are no direct instances of Animal

All objects are either lions or elephants

Abstract class

Abstract operationCommunication

Discriminator

Abstract and Concrete Classes

Abstract classes cannot have any objects Concrete classes can have objects

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 94

Airplane Helicopter Wolf Horse

FlyingThing Animal

Bird

multipleinheritance

Use multiple inheritance only when needed, andalways with caution !

Review: Multiple Inheritance

A class can inherit from several otherclasses

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 95

Name clashes on attributes or operations

Repeated inheritance

FlyingThingcolor

getColor

Animalcolor

getColor

Bird

FlyingThing Animal

Bird

AnimateObjectcolor

Multiple Inheritance: Problems

Resolution of these problems is implementation-dependent

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 96

Generalization Constraints

Complete End of the inheritance tree

Incomplete Inheritance tree may be extended

Disjoint Subclasses mutually exclusive Doesn’t support multiple inheritance

Overlapping Subclasses are not mutually exclusive Supports multiple inheritance

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 97

Example: Generalization Constraints

Asset

RealEstate

Bank Account Security

Saving Checking Stock Bond

{disjoint}

{disjoint,complete}{disjoint}

End of inheritance hierarchy

Multiple inheritancenot supported

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 98

Example: Generalization Constraints (cont.)

Vehicle

WaterVehicle

LandVehicle

Amphibious Vehicle

{overlapping}

Multiple inheritancesupported

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 99

W i n d o w

WindowWithScrollbar

Scrollbar

Is this correct?

Generalization vs. Aggregation

Generalization and aggregation are oftenconfused Generalization represents an “is-a” or “kind-of”

relationship Aggregation represents a “part-of” relationship

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 100

Scrollbar

Window

WindowWithScrollbar11

W i n d o w

WindowWithScrollbar

Scrollbar

A WindowWithScrollbar “is a” WindowA WindowWithScrollbar “contains a” Scrollbar

Generalization vs. Aggregation

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 101

Generalization Uses

Share Common Properties and Behavior Share Implementation Implement Polymorphism Implement Metamorphosis

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 102

Generalization Uses

Share Common Properties and Behavior Share Implementation Implement Polymorphism Implement Metamorphosis

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 103

List

insertTop (Item)insertBottom (Item)removeTop ()removeBottom ()insert (Item, position)

Stack

Animal

talk ()

Lion Tiger

talk () talk ()

Do these classes follow the IS-A style of programming?

Generalization: Share Common Properties and Behavior

Follows the Is-A style of programming Class substitutability

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 104

Animal

talk ()

Lion Tiger

talk () talk ()

Generalization: Share Common Properties and Behavior (contd)

List

insertTop (Item)insertBottom (Item)removeTop ()removeBottom ()insert (Item, position)

Stack

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 105

Generalization Uses

Share Common Properties and Behavior Share Implementation Implement Polymorphism Implement Metamorphosis

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 106

List

insertBottom (Item)removeBottom ()insert (Item, position)

Stack

SequentialContainer

insertTop (Item)removeTop ()

List

insertTop (Item)insertBottom (Item)removeTop ()removeBottom ()insert (Item, position)

Stack

Generalization: Share Implementation: Factoring

Supports the reuse of the implementation ofanother class

Cannot be used if the class you want to“reuse” cannot be changed

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 107

List

insertBottom (Item)removeBottom ()insert (Item, position) remove (position)

Stack

push (Item)pop (): Item 11

List

insertTop (Item)insertBottom (Item)removeTop ()removeBottom ()insert (Item, position)

Stack

Generalization Alternative: Share Implementation: Delegation

Supports the reuse of the implementation ofanother class

Can be used if the class you want to “reuse”cannot be changed

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 108

List

insertBottom (Item)removeBottom ()insert (Item, position)remove (position)insertTop (Item)

Stack

push (Item)pop ()

push() and pop() can accessmethods of List but instances ofStack cannot

<<implementation>>

Implementation Inheritance

Ancestor public operations, attributes andrelationships are NOT visible to clients ofdescendent class instances

Descendent class must define all access toancestor operations, attributes, andrelationships

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 109

Generalization Uses

Share Common Properties and Behavior Share Implementation Implement Polymorphism Implement Metamorphosis

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 110

Manufacturer AManufacturer B

Manufacturer C

OO Principle:Encapsulation

Review: What is Polymorphism?

The ability to hide many differentimplementations behind a single interface

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 111

Generalization: Implement Polymorphism

Without Polymorphism With Polymorphism

Animal

talk ()

Lion Tiger

talk () talk ()

if animal = “Lion” thendo the Lion talk

else if animal = “Tiger” thendo the Tiger talk

end

do the Animal talk

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 112

Polymorphism: Use of Interfaces vs. Generalization

Interfaces support implementation-independentrepresentation of polymorphism Realization relationships can cross

generalization hierarchies Interfaces are pure specifications, no behavior

Abstract base class may define attributes andassociations

Interfaces are totally independent of inheritance Generalization is used to re-use implementations Interfaces are used to re-use behavioral

specifications Generalization provides a way to implement

polymorphism

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 113

Polymorphism Via Generalization Design Decisions

Provide interface only to descendant classes? Design ancestor as an abstract class All methods provided by descendent classes

Provide interface and default behavior todescendent classes? Design ancestor as a concrete class with a

default method Allow polymorphic operations

Provide interface and mandatory behavior todescendent classes? Design ancestor as a concrete class Do not allow polymorphic operations

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 114

Generalization Uses

Share Common Properties and Behavior Share Implementation Implement Polymorphism Implement Metamorphosis

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 115

Metamorphosis exists in the real worldHow should it be modeled?

What is Metamorphosis?

Metamorphosis 1. a change in form, structure, or function;

specifically the physical change undergone bysome animals, as of the tadpole to the frog

2. any marked change, as in character,appearance, or condition

Webster’s New World Dictionary, Simon &Schuster, Inc., 1979

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 116

FulltimeStudentnameaddressstudentIDgradDate

ParttimeStudentnameaddress

maxNumCoursesstudentID

Example: Metamorphosis

In the university, there are full time studentsand part time students Full time students have an expected graduation

date but part time students do not Part time students may take a maximum of 3

courses where there is no maximum for fulltime students

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 117

What happens if a part-time student

becomes a full-timestudent?

FulltimeStudent

StudentnameaddressstudentID

gradDate

ParttimeStudent

maxNumCourses

Modeling Metamorphosis: One Approach

An generalization relationship may becreated

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 118

1 1 Classification

ParttimeClassificationmaxNumCourses

StudentnameaddressstudentID

FulltimeClassificationgradDate

FulltimeStudent

StudentnameaddressstudentID

gradDate

ParttimeStudent

maxNumCourses

Modeling Metamorphosis: Another Approach

Inheritance may be used to model commonstructure, behavior and/or relationships tothe “changing” parts

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 119

: Student : FulltimeClassification

: StudentManager

: ParttimeClassification

delete

create

change to full time

Modeling Metamorphosis: Another Approach (contd)

Metamorphosis is accomplished by theobject “talking” to the changing parts

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 120

studentID

11ResidentInformation

dormroomroomKeyID

Studentnameaddress10..1 10..1

Classification1

Metamorphosis and Flexibility

This technique also adds to the flexibility ofthe model

ParttimeClassificationmaxNumCourses

FulltimeClassificationgradDate

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 121

Exercise: Define Generalizations

Given the following: All design classes

Identify the following: Any refinements to existing generalizations Any new applications of generalization

• Make sure any metamorphosis is considered Produce the following diagrams:

Class diagram containing any new and/orrefined generalization relationships betweenclasses

(optional) Refined use-case realizations

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 122

Class Design Steps

Create Initial Design Classes Identify Persistent Classes Define Operations Define Class Visibility Define Methods Define States Define Attributes Define Dependencies Define Associations Define Generalizations Resolve Use-Case Collisions Handle Non-Functional Requirements in General Checkpoints

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 123

Resolve Use-Case Collisions

Multiple use cases may simultaneously accessdesign objects

Options Use synchronous messaging => first-come

first-serve order processing Identify operations (or code) to protect Apply access control mechanisms

• Message queuing• Semaphores (or 'tokens')• Other locking mechanism

Resolution is highly dependent on implementationenvironment

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 124

Class Design Steps

Create Initial Design Classes Identify Persistent Classes Define Operations Define Class Visibility Define Methods Define States Define Attributes Define Dependencies Define Associations Define Generalizations Resolve Use-Case Collisions Handle Non-Functional Requirements in General Checkpoints

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 125

Handle Non-Functional Requirements in General

Analysis Class Analysis Mechanism(s)

StudentScheduleCourseOfferingCourseRegistrationController

Persistency, Security

Persistency, Legacy InterfacePersistency, Legacy InterfaceDistribution

Persistency, Security

Analysis Design Implementation

Remote MethodInvocation (RMI)

Persistency

AnalysisMechanism

(Conceptual)

DesignMechanism(Concrete)

ImplementationMechanism

(Actual)

OODBMS

RDBMSJDBC

ObjectStore

Java 1.2 from Sun

Legacy Data

NewData

Distribution

Persistency

DesignGuidelines

Some DesignClass

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 126

Class Design Steps

Create Initial Design Classes Identify Persistent Classes Define Operations Define Class Visibility Define Methods Define States Define Attributes Define Dependencies Define Associations Define Generalizations Resolve Use-Case Collisions Handle Non-Functional Requirements in General Checkpoints

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 127

Checkpoints: Classes

Does the name of each class clearly reflect the role itplays?

Does the class represent a single well-definedabstraction?

Are all attributes and responsibilities functionally coupled? Are there any class attributes, operations or relationships

that should be generalized, that is, moved to an ancestor? Are all specific requirements on the class addressed? Are the demands on the class consistent with any

statecharts which model the behavior of the class and itsinstances?

Is the complete life cycle of an instance of the classdescribed?

Does the class offer the required behavior?

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 128

Checkpoints: Operations

Are the operations understandable? Is the state description of the class and its objects'

behavior correct? Does the class offer the behavior required of it? Have you defined the parameters correctly Have you assigned operations for the messages

of each object completely? Are the implementation specifications (if any) for

an operation correct? Do the operation signatures conform to the

standards of the target programming language? Are all the operations needed by the use-case

realizations?

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 129

Checkpoints: Attributes

Does each attribute represent a singleconceptual thing?

Are the names of the attributes descriptive? Are all the attributes needed by the use-

case realizations?

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 130

Checkpoints: Relationships

Are the role names descriptive? Are the multiplicities of the relationships

correct?

OOAD Using the UML - Class Design, v 4.2Copyright © 1998-1999 Rational Software, all rights reserved 131

Review: Class Design

What is the purpose of Class Design? In what ways are classes refined? Are statecharts created for every class? What are the major components of a

statechart? Provide a brief description ofeach.

What kind of relationship refinements occur? What is the difference between an

association and a dependency? What is done with operations and attributes?