Anda di halaman 1dari 23

Ch.

15 Class Design

Object-Oriented Modeling and Design with UML;


Michael Blaha, James Rumbaugh

2006. 5. 17
Seok-Joong Woo
Contents

™ Introduction
™ Bridging the gap
™ Realizing use cases
™ Designing algorithms
™ Recursing downward
™ Refactoring
™ Design optimization
™ Reification of behavior
™ Adjustment of inheritance
™ Organizing a class design
™ Summary

2006-05-17 2/21
Introduction

™ Class design
ƒ Augment and adjust the real-world models from
analysis
• Complete the definition of the classes and
associations
• Choose algorithms for operation

2006-05-17 3/21
Bridging the gap

™ Inventing intermediate element


ƒ Bridge the gap between the desired features and
the available resources
Web-based operating system

Desired features

Intermediate
The gap
elements ?

Available resources

Spreadsheet, programming language

Operations, classes, other UML constructs

2006-05-17 4/21
Realizing use cases

™ Purpose
ƒ Use cases define the required behavior without
realization
ƒ Design must invent new operations and new
object that provide this behavior
™ Steps
ƒ List the responsibilities of use case or operation
ƒ Define an operation for each responsibility
ƒ Assign the new low-level operations to classes

2006-05-17 5/21
Designing algorithms(1/2)

™ Algorithm shows how operation is done


™ Steps
ƒ Choosing algorithms
• Computational complexity
• Ease of implementation and understandability
• Flexibility

2006-05-17 6/21
Designing algorithms(2/2)

™ Steps(cont’d)
ƒ Choosing data structures
ƒ Defining internal classes and operations
ƒ Assigning operations to classes
• Receiver of action
• Query vs. update Person
User
친지 Vehicle
학생 Rectangle
선생님
Move
• Focal class 공부Resize
공부
공부

• Analogy to real world 부모님

2006-05-17 7/21
Recursing downward(1/3)

™ Design process generally works top down


ƒ Start with the higher-level operations and
proceed to define lower-level operations
™ Approach
ƒ Functionality layers
• Take the required high-level functionality and break
it into lesser operations
• Practical tip
– Combine similar operations, attach operations to
classes
– Attach operations to classes and broaden them for
reuse

2006-05-17 8/21
Recursing downward(3/3)

Designed functionality layers Designed mechanisms layers

Brittle, sensitive to changes Doesn’t actually do anything


in requirements useful

System mixes functionality and mechanism layers

2006-05-17 9/21
Recursing downward(3/3)

™ Approach(cont’d)
ƒ Mechanism layers
• Build the system out of layer of needed support
mechanisms
– Such as data structures, algorithms
• Don’t show up high-level responsibilities of a system
but they are needed to make it all work

2006-05-17 10/21
Refactoring

™ Initial design contain inconsistencies,


redundancies, and inefficiencies
™ Improve software design without external
functionality
ƒ Look across many different classes and operations,
and reorganize them

2006-05-17 11/21
Design optimization(1/3)

™ Designing system is to first get the logic correct


and then optimize it
ƒ Because difficult to optimize a design at the same
time as create it
™ Approach
ƒ Provide efficient access paths
ƒ Rearrange execution order for efficiency
ƒ Save intermediate results to avoid recomputation

2006-05-17 12/21
Design optimization(2/3)

™ Provide efficient access paths


Employs HasSkill
Company Person Skill
1 * * *

Analysis model for person skills

/SpeaksLanguage
*
language *
Employs HasSkill
Company Person Skill
1 * * *

Design model for person skills

2006-05-17 13/21
Design optimization(3/3)

™ Rearrange execution order for efficiency


ƒ Optimize the algorithm
™ Save intermediate results to avoid recomputation
ƒ Explicit update
ƒ Periodic recomputation
ƒ Active values

2006-05-17 14/21
Reification of behavior

™ Promotion of behavior into class


ƒ Reify behavior as possible store, pass it to other
operations, and transform it
™ Method
ƒ Encoding it into an object,decoding it when it is run

2006-05-17 15/21
Adjustment of inheritance(1/2)

™ Adjust the definitions of classes and operations


to increase inheritance
™ Steps
ƒ Rearrange classes and operations
• Operations with optional arguments
• Operations that are special cases
• Inconsistent names
• Irrelevant operations

2006-05-17 16/21
Adjustment of inheritance(2/2)

™ Abstract out common behavior


ƒ Creation a common superclass
™ Use delegation to share behavior

List

add Discouraged design


remove (with implementation
first inheritance)
last

Stack
push
pop

2006-05-17 17/21
Adjustment of inheritance(2/2)

™ Abstract out common behavior


ƒ Creation a common superclass
™ Use delegation to share behavior

Stack List
Recommended design
body:list{private} (with delegation)
add
push * 1 remove
pop first
last

2006-05-17 18/21
Organizing a class design(1/2)

™ Information hiding
ƒ Separate external specification from internal
implementation
ƒ Ways
• Limit the scope of class-model traversals
• Do not directly access foreign attributes
• Define interfaces at a high level of abstraction
• Hide external objects
• Avoid cascading method calls

2006-05-17 19/21
Organizing a class design(2/2)

™ Coherence of entities
ƒ Separate policy and implementation
• Policy
– Making of context-dependent decision
• Implementation
– Execution of fully-specified algorithms
™ Fine-tuning packages

2006-05-17 20/21
Summary

™ Class design involves the following


ƒ Bridging the gap
ƒ Realizing use cases
ƒ Designing algorithms
ƒ Recursing downward
ƒ Refactoring
ƒ Design optimization
ƒ Reification of behavior
ƒ Adjustment of inheritance
ƒ Organizing a class design

2006-05-17 21/21
Encapsulation

Abstraction

Information
hiding

2006-05-17
Dictionary of terms

™ Associations : Relationship between two or more classifiers that involves


connections among their instances
™ Classifier : A model element that describes behavioral and structural
features.
™ feature : A property such as operation or attribute, which is
encapsulated as part of a list within a classifier, such as an interface, a
class, or a datatype
™ realization : the relationship between a specification and its
implementation; an indication of the inheritance of behavior without the
inheritance of structure
ƒ specification : set of requirement declarative description of what
something is or does, for example use case, interface…. contrast :
implementation
ƒ implementation : how something is constructed or computed, a method
is an implementation of an operation. …contrast :specification

2006-05-17

Anda mungkin juga menyukai