Object Design
Object Design
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 2
Possible solution for exercise 6.4
EmailFrontEnd FaxFrontEnd
ProblemReporting
StorageSubsystem NotificationSubsystem
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 3
Exercise 6.5
6.5 You are designing the access control policies for a Web-
based retail store:
w Customers access the store via the Web, browse product
information, input their address and payment information, and
purchase products.
w Suppliers can add new products, update product information,
and receive orders.
w The store owner sets the retail prices, makes tailored offers to
customers based on their purchasing profiles, and provides
marketing services.
You have to deal with three actors: StoreAdministrator,
Supplier, and Customer. Design an access control policy for
all three actors. Customers can be created via the Web,
whereas Suppliers are created by the StoreAdministrator.
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 4
Possible solution for exercise 6.5
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 5
Object Design
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 6
A2: Application Server A1: Application Server
State Profil
State Profil
State Profil
State Profil
State Profil
State
Database Server
(Database Framework)
HTTP
Application objects
Solution objects
Custom objects
Off-the-shelf components
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 10
Terminology of Activities
♦ Object-Oriented Methodologies
w System Design
t Decomposition into subsystems
w Object Design
t Implementation language chosen
t Data structures and algorithms chosen
♦ SA/SD (structured analysis/structured design) uses different
terminology:
w Preliminary Design
t Decomposition into subsystems
t Data structures are chosen
w Detailed Design
t Algorithms are chosen
t Data structures are refined
t Implementation language is chosen
t Typically in parallel with preliminary design, not separate stage
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 11
Object Design Activities
1. Service specification
w Describes precisely each class interface
2. Component selection
w Identify off-the-shelf components and additional solution objects
3. Object model restructuring
w Transforms the object design model to improve its
understandability and extensibility
4. Object model optimization
w How to address nonfunctional requirements
w Transforms the object design model to address performance criteria
such as response time or memory utilization.
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 12
Service Specification
♦ Requirements analysis
w Identifies attributes and operations without specifying their types or
their parameters.
♦ Object design
w Add visibility information
w Add type signature information
w Add contracts (Bertrand Meyer, Eiffel)
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 13
Add Visibility
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 14
Information Hiding Heuristics
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 15
Information Hiding Design Principles
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 16
Add Type Signature Information
Hashtable
-numElements:int
+put()
+get()
+remove()
+containsKey()
+size()
Hashtable
-numElements:int
+put(key:Object,entry:Object)
+get(key:Object):Object
+remove(key:Object)
+containsKey(key:Object):boolean
+size():int
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 17
Contracts
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 18
Expressing constraints in UML
♦ OCL (Object Constraint Language)
w OCL allows constraints to be formally specified on single model
elements or groups of model elements
w A constraint is expressed as an OCL expression returning the value
true or false. OCL is not a procedural language (cannot constrain
control flow).
♦ OCL expressions for Hashtable operation put():
w Invariant:
Context is a class OCL expression
t context Hashtable inv: numElements
operation >= 0
w Precondition:
t context Hashtable::put(key, entry) pre:!containsKey(key)
w Post-condition:
t context Hashtable::put(key, entry) post: containsKey(key) and
get(key) = entry
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 19
Expressing Constraints in UML
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 20
Object Design Areas
1. Service specification
w Describes precisely each class interface
2. Component selection
w Identify off-the-shelf components and additional solution objects
3. Object model restructuring
w Transforms the object design model to improve its
understandability and extensibility
4. Object model optimization
w Transforms the object design model to address performance criteria
such as response time or memory utilization.
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 21
Component Selection
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 22
Reuse...
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 23
Object Design Areas
1. Service specification
w Describes precisely each class interface
2. Component selection
w Identify off-the-shelf components and additional solution objects
w Use the bridge pattern if the off-the-shelf component comes late
t Use a quick and dirty implementation first
3. Object model restructuring
w Transforms the object design model to improve its
understandability and extensibility
4. Object model optimization
w Transforms the object design model to address performance criteria
such as response time or memory utilization.
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 24
Restructuring Activities
♦ Realizing associations
♦ Revisiting inheritance to increase reuse
♦ Revising inheritance to remove implementation dependencies
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 25
Realizing Associations
♦ Strategy for implementing associations:
w Be as uniform as possible
w Individual decision for each association
♦ Example of uniform implementation
w 1-to-1 association:
t Role names are treated like attributes in the classes and translate to
references
w 1-to-many association:
t "Ordered many" : Translate to Vector
t "Unordered many" : Translate to Set
w Qualified association:
t Translate to Hash table
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 26
Unidirectional 1-to-1 Association
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 27
Bidirectional 1-to-1 Association
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 28
1-to-Many Association
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 29
Qualification
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 30
Increase Inheritance
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 31
Building a super class from several classes1/11/01
♦ Prepare for inheritance. All operations must have the same
signature but often the signatures do not match:
w Some operations have fewer arguments than others: Use
overloading (Possible in Java)
w Similar attributes in the classes have different names: Rename
attribute and change all the operations.
w Operations defined in one class but no in the other: Use virtual
functions and class function overriding.
♦ Abstract out the common behavior (set of operations with same
signature) and create a superclass out of it.
♦ Superclasses are desirable. They
w increase modularity, extensibility and reusability
w improve configuration management
♦ Turn the superclass into an abstract interface if possible
w Use Bridge pattern
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 32
Object Design Areas
1. Service specification
w Describes precisely each class interface
2. Component selection
w Identify off-the-shelf components and additional solution objects
3. Object model restructuring
w Transforms the object design model to improve its
understandability and extensibility
4. Object model optimization
w Transforms the object design model to address performance criteria
such as response time or memory utilization.
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 33
Design Optimizations
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 34
Design Optimization Activities
1. Add redundant associations:
w What are the most frequent operations? ( Sensor data lookup?)
w How often is the operation called? (30 times a month, every 50
milliseconds)
2. Rearrange execution order
w Eliminate dead paths as early as possible (Use knowledge of
distributions, frequency of path traversals)
w Narrow search as soon as possible
w Check if execution order of loop should be reversed
3. Turn classes into attributes
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 35
Implement Application domain classes
♦ To collapse or not collapse: Attribute or association?
♦ Object design choices:
w Implement entity as embedded attribute
w Implement entity as separate class with associations to other
classes
♦ Associations are more flexible than attributes but often
introduce unnecessary indirection.
♦ Abbott's textual analysis rules
♦ Every student receives an immatriculationnumber at the first
day in TUM.
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 36
Optimization Activities: Collapsing Objects
Matrikelnumber
Student ID:String
Student
Matrikelnumber:String
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 37
To Collapse or not to Collapse?
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 38
Design Optimizations (continued)
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 39
Optimization Activities: Delaying Complex
Computations Image
filename:String
data:byte[]
width()
height()
paint()
Image
filename:String
width()
height()
paint()
image
ImageProxy RealImage
1 0..1
filename:String data:byte[]
width() width()
height() height()
paint() paint()
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 40
Documenting the Object Design: The Object Design
Document (ODD)
♦ Object design document
w Same as RAD +...
w … + additions to object, functional and dynamic models (from solution
domain)
w … + Navigational map for object model
w … + Javadoc documentation for all classes
♦ ODD Management issues
w Update the RAD models in the RAD?
w Should the ODD be a separate document?
w Who is the target audience for these documents (Customer, developer?)
w If time is short: Focus on the Navigational Map and Javadoc
documentation?
♦ Example of acceptable ODD:
w [Link]
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 41
Documenting Object Design: ODD Conventions
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 42
JavaDoc
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 43
More on JavaDoc
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 44
Class and Interface Doc Tags
@author name-text
w Creates an “Author” entry.
@version version-text
w Creates a “Version” entry.
@see classname
w Creates a hyperlink “See Also classname”
@since since-text
w Adds a “Since” entry. Usually used to specify that a feature or
change exists since the release number of the software specified in
the “since-text”
@deprecated deprecated-text
w Adds a comment that this method can no longer be used.
Convention is to describe method that serves as replacement
w Example: @deprecated Replaced by setBounds(int, int, int, int).
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 45
Constructor and Method Doc Tags
♦ Can contain @see tag, @since tag, @deprecated as well as:
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 46
Example of a Class Doc Comment
/**
* A class representing a window on the screen.
* For example:
* <pre>
* Window win = new Window(parent);
* [Link]();
* </pre>
*
* @author Sami Shaio
* @version %I%, %G%
* @see [Link]
* @see [Link]
*/
class Window extends BaseWindow {
...
}
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 47
Example of a Method Doc Comment
/**
* Returns the character at the specified index. An index
* ranges from <code>0</code> to <code>length() - 1</code>.
*
* @param index the index of the desired character.
* @return the desired character.
* @exception StringIndexOutOfRangeException
* if the index is not in the range <code>0</code>
* to <code>length()-1</code>.
* @see [Link]#charValue()
*/
public char charAt(int index) {
...
}
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 48
Example of a Field Doc Comment
/**
* The X-coordinate of the window.
*
* @see window#1
*/
int x = 1263732;
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 49
Example: Specifying a Service in Java
/** @Return Returns the name of the office. Requires, that Office has
been initialized with a name */
public string GetName();
....
}
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 50
Implementation of Application Domain Classes
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 51
Application Domain vs Solution Domain Objects
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 52
Package it all up
♦ Pack up design into discrete physical units that can be edited,
compiled, linked, reused
♦ Construct physical modules
w Ideally use one package for each subsystem
w System decomposition might not be good for implementation.
♦ Two design principles for packaging
w Minimize coupling:
t Classes in client-supplier relationships are usually loosely coupled
t Large number of parameters in some methods mean strong coupling
(> 4-5)
t Avoid global data
w Maximize cohesiveness:
t Classes closely connected by associations => same package
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 53
Packaging Heuristics
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 54
Summary
♦ Object design closes the gap between the requirements and the
machine.
♦ Object design is the process of adding details to the
requirements analysis and making implementation decisions
♦ Object design includes:
1. Service specification
2. Component selection
3. Object model restructuring
4. Object model optimization
♦ Object design is documented in the Object Design Document,
which can be generated using tools such as JavaDoc.
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 55