Object Design: Reuse and Patterns I
Object Design: Reuse and Patterns I
Object Design: Reuse and Patterns I
Application objects
Solution objects
Custom objects
Object design gap
Off-the-shelf components
Machine
Examples of Object Design Activities
Select Subsystem
Specification Reuse
Identifying missing
Identifying components
attributes & operations
Specifying visibility
Adjusting components
Specifying types &
signatures
Identifying patterns
Specifying constraints
Restructuring Optimization
Delaying complex
Realizing associations computations
A Little Bit of Terminology: Activities
Object-Oriented methodologies use these terms:
System Design Activity
Decomposition into subsystems
Object Design Activity
Implementation language chosen
Data structures and algorithms chosen
Structured analysis/structured design uses these terms:
Preliminary Design Activity
Decomposition into subsystems
Data structures are chosen
Detailed Design Activity
Algorithms are chosen
Data structures are refined
Implementation language is chosen
Typically in parallel with preliminary design, not a separate activity
Plan for the next Lectures Today we
Start here
Reuse Concepts
The use of inheritance
Implementation vs Interface Inheritance
Delegation
Components
Documenting the Object Design
JavaDoc
Reuse Concepts
[Gamma et al 94]:
Strict modeling of the real world leads to a system that reflects
today’s realities but not necessarily tomorrow’s.
Inheritance Object
Design
Analysis
activity
Taxonomy Inheritance
for Reuse
Mammal
Implementation inheritance
Also called class inheritance
Goal: Extend an applications’ functionality by reusing functionality
in parent class
Inherit from an existing class with some or all operations already
implemented
Interface inheritance
Also called subtyping
Inherit from an abstract class with all operations specified, but not
yet implemented
Delegation as alternative to Implementation
Inheritance
Remove()
+Push() Add()
Stack +Pop()
+Top()
+Push()
+Pop()
+Top()
Comparison: Delegation vs Implementation Inheritance
Delegation
Pro:
Flexibility: Any object can be replaced at run time by another one (as
long as it has the same type)
Con:
Inefficiency: Objects are encapsulated.
Inheritance
Pro:
Straightforward to use
Supported by many programming languages
Easy to implement new functionality
Con:
Inheritance exposes a subclass to the details of its parent class
Any change in the parent class implementation forces the subclass to
change (which requires recompilation of both)
Lecture on
Design Patterns
Select existing
off-the-shelf class libraries
frameworks or
components
Adjust the class libraries, framework or components
Change the API if you have the source code.
Use the adapter or bridge pattern if you don’t have access
Architecture Driven Design
Reuse...
Whitebox frameworks:
Extensibility achieved through inheritance and dynamic binding.
Existing functionality is extended by subclassing framework base
classes and overriding predefined hook methods
Often design patterns such as the template method pattern are used
to override the hook methods.
Blackbox frameworks
Extensibility achieved by defining interfaces for components that
can be plugged into the framework.
Existing functionality is reused by defining components that
conform to a particular interface
These components are integrated with the framework via
delegation.
Class libraries and Frameworks
Class Libraries:
Less domain specific
Provide a smaller scope of reuse.
Class libraries are passive; no constraint on control flow.
Framework:
Classes cooperate for a family of related applications.
Frameworks are active; affect the flow of control.
In practice, developers often use both:
Frameworks often use class libraries internally to simplify the
development of the framework.
Framework event handlers use class libraries to perform basic tasks
(e.g. string processing, file management, numerical analysis…. )
Components and Frameworks
Components
Self-contained instances of classes
Plugged together to form complete applications.
Blackbox that defines a cohesive set of operations,
Can be used based on the syntax and semantics of the interface.
Components can even be reused on the binary code level.
The advantage is that applications do not always have to be recompiled
when components change.
Frameworks:
Often used to develop components
Components are often plugged into blackbox frameworks.
Example: Framework for Building Web Applications
WebObjects
WebBrowser
WebServer WebObjectsApplication
WOAdaptor
WORequest
WoRequest
StaticHTML Template EOF
RelationalDatabase
Documenting the Object Design: The Object Design
Document (ODD)
Object design document
Same as the Requirements Analysis Document (RAD) plus...
… additions to object, functional and dynamic models (from solution
domain)
… navigational map for object model
… Javadoc documentation for all classes
ODD Management issues
Update the system models in the RAD?
Should the ODD be a separate document?
Who is the target audience for these documents (Customer, developer?)
If time is short: Focus on the Navigational Map and Javadoc
documentation?
ODD Template:
http://www.oose.org
Documenting Object Design: ODD Conventions
/**
* The X-coordinate of the window.
*
* @see window#1
*/
int x = 1263732;
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();
....
}
Package it all up
Pack up design into discrete physical units that can be edited,
compiled, linked, reused
Construct physical modules
Ideally use one package for each subsystem
System decomposition might not be good for implementation.
Two design principles for packaging
Minimize coupling:
Classes in client-supplier relationships are usually loosely coupled
Large number of parameters in some methods mean strong coupling
(> 4-5)
Avoid global data
Maximize cohesion:
Classes closely connected by associations => same package
Packaging Heuristics
State Profil
State Profil
State Profil
State Profil
State Profil
State
Database Server
(Database Framework)
HTTP
Main goal:
Reuse knowledge from previous experience to current problem
Reuse functionality already available
Composition (also called Black Box Reuse)
New functionality is obtained by aggregation
The new object with more functionality is an aggregation of existing
components
Inheritance (also called White-box Reuse)
New functionality is obtained by inheritance.
Three ways to get new functionality:
Implementation inheritance
Interface inheritance
Delegation
Reuse Heuristics