System Design
System Design
2
Why is Design so Difficult?
3
The Purpose of System Design
Problem
Existing System
4
System Design
System Design
1. Design Goals
Definition
8. Boundary
Trade-offs Conditions
Initialization
Termination
Failure
2. System
Decomposition
Layers/Partitions
7. Software
Cohesion/Coupling
Control
Monolithic
Event-Driven
3. Concurrency Threads
Identification of
4. Hardware/ 6. Global Conc. Processes
Threads Software 5. Data Resource Handling
Mapping Management Access control
Special purpose Persistent Objects Security
Buy or Build Trade-off Files
Databases
Allocation Data structure
Connectivity
5
Overview
System Design
0. Overview of System Design
1. Design Goals
2. Subsystem Decomposition
3. Concurrency
4. Hardware/Software Mapping
5. Persistent Data Management
6. Global Resource Handling and Access Control
7. Software Control
8. Boundary Conditions
6
How to use the results from the Requirements Analysis for System
Design
7
How do we get the Design Goals?
8
Establish New Design Goals
9
Sharpen the Design Goals
! Location-based input
⬥ Input depends on user location
⬥ Input depends on the direction where the user
looks (“egocentric systems”)
! Multi-modal input
⬥ The input comes from more than one input device
! Dynamic connection
⬥ Contracts are only valid for a limited time
! Isthere a possibility of further generalizations?
! Example: location can be seen as a special case of context
⬥ User preference is part of the context
⬥ Interpretation of commands depends on context
10
List of Design Goals
♦ Reliability
! Good documentation
♦ Modifiability
! Well-defined interfaces
♦ Maintainability
! User-friendliness
♦ Understandability
! Reuse of components
♦ Adaptability
! Rapid development
♦ Reusability
! Minimum # of errors
♦ Efficiency
! Readability
♦ Portability
! Ease of learning
♦ Traceability of requirements
! Ease of remembering
♦ Fault tolerance
! Ease of use
♦ Backward-compatibility
! Increased productivity
♦ Cost-effectiveness
! Low-cost
♦ Robustness
! Flexibility
♦ High-performance
11
Relationship Between Design Goals
End User
Low cost
Functionality
Increased Productivity
User-friendliness
Backward-Compatibility
Ease of Use
Traceability of requirements
Runtime
Ease of learning
Rapid development
Efficiency Fault tolerant
Flexibility Robustness
Reliability
Portability
Client Good Documentation
Minimum # of errors
Modifiability, Readability
Reusability, Adaptability
Well-defined interfaces
Developer/
Maintainer
12
Typical Design Trade-offs
13
Nonfunctional Requirements may give a clue for the use of Design
Patterns
14
Textual Clues in Nonfunctional Requirements
15
Section 2. System Decomposition
16
Services and Subsystem Interfaces
17
Choosing Subsystems
18
Subsystem Decomposition Example
Authoring
Augmented
Reality
Modeling Workflow
Inspection
Workorder Repair
19
Definition: Subsystem Interface Object
20
System as a set of subsystems communicating via a software bus
!
Authoring
Modeling
!
Workflow
Augmented
Inspection Reality
Repair Workorder
Augmented
Reality
Workflow
Modeling
22
Another Example:
User Interface ARENA Subsystem
decomposition
Tournament
Advertisement User Management
Component
Management
User Directory
Tournament
Session Statistics
Management
23
Services provided by
User Interface ARENA Subsystems
Manages advertisement
banners and Manages tournaments, Administers user
sponsorships. applications, accounts
promotions.
Tournament
Advertisement User Management
Tournament
Session Statistics
Management
Stores user profiles
Stores results of
Maintains state (contact &
archived
during matches. subscriptions)
tournaments
24
Coupling and Cohesion
25
Partitions and Layers
Partitioning and layering are techniques to achieve low
coupling.
A large system is usually decomposed into subsystems using both,
layers and partitions.
♦ Partitions vertically divide a system into several independent
(or weakly-coupled) subsystems that provide services on the
same level of abstraction.
♦ A layer is a subsystem that provides subsystem services to a
higher layers (level of abstraction)
⬥ A layer can only depend on lower layers
⬥ A layer has no knowledge of higher layers
26
Subsystem Decomposition into Layers
A: Subsystem Layer 1
27
Relationships between Subsystems
♦ Layer relationship
⬥ Layer A “Calls” Layer B (runtime)
⬥ Layer A “Depends on” Layer B (“make” dependency, compile time)
♦ Partition relationship
⬥ The subsystem have mutual but not deep knowledge about each
other
⬥ Partition A “Calls” partition B and partition B “Calls” partition A
28
Virtual Machine
♦ Dijkstra: T.H.E. operating system (1965)
⬥ A system should be developed by an ordered set of virtual machines, each built in terms of the ones
below it.
Problem
C1
C1
attr attr
C1
attr VM1
opr opr opr
C1 C1
attr attr VM2
opr opr
C1
C1
attr
attr VM3
opr
opr
C1
attr VM4
opr
Existing System
29
Virtual Machine
♦ A virtual machine is an abstraction
⬥ It provides a set of attributes and operations.
♦ A virtual machine is a subsystem
⬥ It is connected to higher and lower level virtual machines by
"provides services for" associations.
♦ Virtual machines can implement two types of software
architecture
⬥ Open and closed architectures.
30
Closed Architecture (Opaque Layering)
C1 C1 C1
♦ Any layer can only invoke attr
op
attr
op
attr
op
VM1
operations from the
immediate layer below
C1
attr
C1
attr VM2
op op
C1 C1
attr attr VM4
op op
31
Open Architecture (Transparent Layering)
C1 C1 C1
♦ Any layer can invoke operations attr
op
attr
op
attr
op
VM1
from any layers below
C1 C1
♦ Design goal: Runtime attr attr VM2
op op
efficiency C1 C1
attr attr VM3
op op
C1 C1
attr attr VM4
op op
32
Properties of Layered Systems
♦ Layered systems are hierarchical. They are desirable because
hierarchy reduces complexity (by low coupling).
♦ Closed architectures are more portable.
♦ Open architectures are more efficient.
♦ If a subsystem is a layer, it is often called a virtual machine.
♦ Layered systems often have a chicken-and egg problem
⬥ Example: Debugger opening the symbol table when the file system needs
to be debugged
A: Debugger
D: File System
G: Op. System
33
Software Architectural Styles
♦ Subsystem decomposition
⬥ Identification of subsystems, services, and their relationship to each
other.
♦ Specification of the system decomposition is critical.
♦ Patterns for software architecture
⬥ Client/Server
⬥ Peer-To-Peer
⬥ Repository
⬥ Model/View/Controller
⬥ Pipes and Filters
34
Client/Server Architectural Style
Client * *
requester provider service1()
service2()
…
serviceN()
35
Client/Server Architectural Style
♦ Often used in database systems:
⬥ Front-end: User application (client)
⬥ Back end: Database access and manipulation (server)
♦ Functions performed by client:
⬥ Customized user interface
⬥ Front-end processing of data
⬥ Initiation of server remote procedure calls
⬥ Access to database server across the network
♦ Functions performed by the database server:
⬥ Centralized data management
⬥ Data integrity and database consistency
⬥ Database security
⬥ Concurrent operations (multiple user access)
⬥ Centralized processing (for example archiving)
36
Design Goals for Client/Server Systems
♦ Service Portability
⬥ Server can be installed on a variety of machines and operating systems
and functions in a variety of networking environments
♦ Transparency, Location-Transparency
⬥ The server might itself be distributed (why?), but should provide a single
"logical" service to the user
♦ Performance
⬥ Client should be customized for interactive display-intensive tasks
⬥ Server should provide CPU-intensive operations
♦ Scalability
⬥ Server should have spare capacity to handle larger number of clients
♦ Flexibility
⬥ The system should be usable for a variety of user interfaces and end
devices (eg. WAP Handy, wearable computer, desktop)
♦ Reliability
⬥ System should survive node or communication link problems
37
Problems with Client/Server Architectural Styles
38
Peer-to-Peer Architectural Style
♦ Generalization of Client/Server Architecture
♦ Clients can be servers and servers can be clients
♦ More difficult because of possibility of deadlocks
requester
Peer Peer
*
service1()
service2() *
…
provider Client Server
serviceN()
1. updateData
application1:DBUser
database:DBMS
application2:DBUser
2. changeNotification
39
Example of a Peer-to-Peer
Layer
Architectural Style
Application
♦ ISO’s OSI Reference
Model
⬥ ISO = International Presentation
Standard Organization
⬥ OSI = Open System
Interconnection
Session
Level of abstraction
♦ Reference model
defines 7 layers of Transport
network protocols and
strict methods of
communication Network
between the layers.
♦ Closed software DataLink
architecture
Physical
40
OSI model Packages and their Responsibility
♦ The Physical layer represents the hardware interface to the net-work. It
allows to send() and receive bits over a channel.
♦ The Datalink layer allows to send and receive frames without error using
the services from the Physical layer.
♦ The Network layer is responsible for that the data are reliably transmitted
and routed within a network.
♦ The Transport layer is responsible for reliably transmitting from end to end.
(This is the interface seen by Unix programmers when transmitting over
TCP/IP sockets)
♦ The Session layer is responsible for initializing a connection, including
authentication.
♦ The Presentation layer performs data transformation services, such as byte
swapping and encryption
♦ The Application layer is the system you are designing (unless you build a
protocol stack). The application layer is often layered itself.
41
Another View at the ISO Model
• A closed software
Application
architecture
• Each layer is a Presentation Format
UML package
containing a set of Session Connection
objects
Transport Message
Network Packet
DataLink Frame
Physical Bit
42
Middleware Allows Focus On The Application Layer
Application
Presentation Object
CORBA
Session
Transport Socket
Network TCP/IP
DataLink
43
ARENA: The Objectives
!!
•
Provide a framework for tournament
organizers
• to customize the number and sequence of
matchers and the accumulation of expert
rating points
!
•
Provide a framework for game developers
• for developing new games, or for adapting
existing games into the ARENA framework
!
•
Provide an infrastructure for advertisers.
ARENA
!
Functional Requirements
!!
• Spectators must be able to watch
matches in progress
without prior registration and without prior knowledge of the
match
• The operator must be able to add new games.
!
• The Player must be able to:
- ask for a match waiting for another player,
- register for a tournament,
- join to an already waiting match
ARENA
!
Nonfunctional Requirements
!!
• The system must support
• parallel tournaments,
• Each involving up to 64 players
• and several hundreds of spectators.
• The ARENA server must be available 24 hours a day
• The operator must be able to add new games
without modifications to the existing system
• ARENA must be able to dynamically interface to
existing games provided by other game
developers.
ARENA Target Environment
!
Example:
• Users must be able to manage ARENA tournaments
with any Web Browser
• The web page must be validated through the W3C
Markup Validation Service
• Interaction with the ARENA Server must be via
HTTP/1.1.
Development environment
• “ Tournament management will be tested with
Internet Explorer and Firefox”
• “The implementation language will be J2EE”
• “The IDE will be Eclipse 4.3”
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 12
ARENA
!
Software Subsystem Decomposition
!!
!!
!
User Interface
Tournament
User
Advertisement
!!
Management
!!
!! !!
!! !!
!! !!
Component !!
Management User Directory
Tournament
Session
Statistics
Management
Bernd Bruegge & Allen H. Dutoit
!
Object-Oriented Software Engineering: Using UML, Patterns, and Java 16
We first distinguish two main parts of the ARENA subsystem:
- the game organization part of the system, which is
responsible for coordinating Users when organizing a
Tournament, and
- the game playing part, in which Players conduct
individual Matches in the scope of a Tournament.
For the game playing part, the client server architecture may not be
sufficient for synchronous games in which the action of one player can
trigger events for another player
within a relatively short time.
!
Synchronous behavior could be simulated with polling; however,
because of scalability and responsiveness goals, we select a peer-to-
peer architecture in which
MatchFrontEndPeer subsystems provide the user interface and a
GamePeer maintains the state of the matches currently under way and
enforces the game rules.
MatchFrontEndPeers may also communicate directly with each
other for real-time games.
!
To achieve the game independence design goal, ARENA
provides a framework for both the MatchFrontEndPeer and the
GamePeer, while the bulk of the game logic is provided by
customized game-dependent components.
Player
Match
!! !!
!! !!
17
ARENA
!
Object Model (2)
!
Game
!!
!!
!
TicTacToe
!
League TournamentStyle
!!
Chess !!
!! !
!
KOStyle
Tournament !!
!!
!!
RoundRobin
Round
Player Move
Match
initiator
Controller
* 1 repository
Model
1 notifier
subscriber
View
*
59
60
in sintesi
!
• è una applicazione del pattern Observer alle
interfaccie utente (GUI ma non necessariamente)
!
• lunga tradizione in smalltalk
!
• non è propriamente un design patter ma un
“architectural pattern”
– perché i vari ruoli possono essere ricoperti da insiemi di
classi anziché da singole classi
!!
!
• intento
!
disaccoppiare:
– rappresentazione del modello di dominio (model)
– interfaccia utente (view), non necessariamente GUI
– controllo dell’interazione uomo-macchina (controller)
il pattern MVC
• struttura
Observer: Observer
1 visualizzato da
*
Model View
1 *
Observer:
Subject Modifiche apportate da più controller
contemporaneamente possono essere
molto difficili da gestire (transazioni,
semafori, ecc)
* *
modificato da
Controller
stimolato da
ESERCIZIO
il pattern MVC
!!
dai il diagramma di sequenza
equivalente a questo
collaboration diagram per le
• interazione due varianti di Observer
!
Observer: Subject
!!
1.3.1.1: getState !
Observer: Observer
aModel
aView
1.3.1: update
1.2.1: notify
dipende dalla
variante di 1: event
Observer usata aController
1.2*: modify 1.1: enable/disable
1.3: notify
(se necessario)
qui, per semplificare, supponiamo che il modello sia
rappresentato da un solo oggetto, osservato con una sola
view e controllato con un solo controller 4
controller: vari punti di vista
!!
possiamo individuare due punti di vista rispetto al
ruolo de controller
– punto di vista vicino a model
• il controller dovrebbe raggruppare le azioni/transazioni “compesse”
che possono essere effettuate sul modello
• è del tutto indipendente da aspetti tecnologici legati all’interfaccia
grafica
– punto di vista vicino alla view
• il controller gestisce eventi (mouse clicks)
• deve fornisce una interfaccia che sia “compatibile” con il toolkit
grafico utilizzato
• può rappresentare il concetto di azione “elementare” effettuabile
tramite l’interfaccia grafica
– abilitazione/disabilitazione, nomi, tooltip, ecc.
9
!!
– ciascuna categoria soddisfa una delle esigenze
!
– categorie:
• controller (propriamente detti)
– tutto ciò che non è legato al toolkit grafico
• azioni
– tutto ciò che è legato a toolkit grafico
– sono spesso classi molto piccole che delegano la maggior parte delle
attivitè al controller
!!
– possono essere considerate degli adapter verso il controller
!!
!
10
MVC: architettura target
!!
!
vari modi di interagire
con il sistema
View1 ViewN
!!
«use» !
package ...
!
package
!!
«use»
!! !! actions
!!
actions !!
Library1 !
«query»
«query»
Library2
Controller
rappresentazione delle
“procedure utente”
package
!!
(vedi use cases)
!
«modify»
impatto: medio
probabilità: media, Controller
dipende dalla
!! !!
package
accuratezza dell’analisi
! !!
impatto: alto
Model
probabilità: media
package
dipende dall’accuratezza
dell’analisi e del porgetto 12
MVC: dettagli di progetto
!
«interface» 1
!! getState
!!
Model !!
!! !!
«interface»
!
1
MutableModel
update
«interface»
1 1 * Observer
ModelImpl ObservableModel
1 1 attach
notify *
View
*
modify
*
1(*)
*
Controller
Action
1
* (ControllerAdapter)
13
14
Sequence of Events (Collaborations)
:FolderView
66
Repository Architectural Style (Blackboard Architecture, Hearsay II
Speech Recognition System)
Repository
Subsystem
createData()
setData()
getData()
searchData()
67
Examples of Repository Architectural Style
Compiler
SemanticAnalyzer
SyntacticAnalyzer
Optimizer
LexicalAnalyzer CodeGenerator
Repository
♦ Hearsay II speech
understanding system
ParseTree SymbolTable
(“Blackboard architecture”)
♦ Database Management
Systems
SourceLevelDebugger SyntacticEditor
♦ Modern Compilers
68
3. Concurrency
69
Concurrency (continued)
70
Concurrency Questions
71
Implementing Concurrency
72
4. Hardware Software Mapping
73
Mapping the Objects
♦ Processor issues:
⬥ Is the computation rate too demanding for a single processor?
⬥ Can we get a speedup by distributing tasks across several
processors?
⬥ How many processors are required to maintain steady state load?
♦ Memory issues:
⬥ Is there enough memory to buffer bursts of requests?
♦ I/O issues:
⬥ Do you need an extra piece of hardware to handle the data
generation rate?
⬥ Does the response time exceed the available communication
bandwidth between subsystems or a task and a piece of hardware?
74
Mapping the Subsystems Associations: Connectivity
♦ Describe the physical connectivity of the hardware
⬥ Often the physical layer in ISO’s OSI Reference Model
⧫ Which associations in the object model are mapped to physical
connections?
⧫ Which of the client-supplier relationships in the analysis/design model
correspond to physical connections?
!
♦ Describe the logical connectivity (subsystem associations)
⬥ Identify associations that do not directly map into physical
connections:
⧫ How should these associations be implemented?
75
DistributedDatabaseArchitecture Tue, Oct 13, 1992 12:53 AM
TCP/IP Ethernet
Logical
LAN
Connectivity
Communication
Agent for
Application Clients LAN Global
Data
Communication Server
Communication
Backbone Network Agent for Data
Agent for OODBMS
Server
Application Clients
Communication Global
Agent for Data Data
Server Server
LAN RDBMS
76
Logical vs Physical Connectivity and the relationship to Subsystem
Layering
Processor 1 Processor 2
77
Hardware/Software Mapping Questions
78
Connectivity in Distributed Systems
♦ If the architecture is distributed, we need to describe the network
architecture (communication subsystem) as well.
♦ Questions to ask
⬥ What are the transmission media? (Ethernet, Wireless)
⬥ What is the Quality of Service (QOS)? What kind of communication
protocols can be used?
⬥ Should the interaction asynchronous, synchronous or blocking?
⬥ What are the available bandwidth requirements between the
subsystems?
⧫ Stock Price Change -> Broker
⧫ Icy Road Detector -> ABS System
79
Drawing Hardware/Software Mappings in UML
♦ System design must model static and dynamic structures:
⬥ Component Diagrams for static structures
⧫ show the structure at design time or compilation time
⬥ Deployment Diagram for dynamic structures
⧫ show the structure of the run-time system
!
♦ Note the lifetime of components
⬥ Some exist only at design time
⬥ Others exist only until compile time
⬥ Some exist at link or runtime
80
Component Diagram
♦ Component Diagram
⬥ A graph of components connected by dependency relationships.
⬥ Shows the dependencies among software components
⧫ source code, linkable libraries, executables
♦ Dependencies are shown as dashed arrows from the client
component to the supplier component.
⬥ The kinds of dependencies are implementation language specific.
♦ A component diagram may also be used to show dependencies
on a façade:
⬥ Use dashed arrow the corresponding UML interface.
81
Component Diagram Example
Scheduler reservations
UML Component
UML Interface
Planner update
GUI
82
Deployment Diagram
83
Deployment Diagram Example
Compile Time!
Dependency
:HostMachine
<<database>>
meetingsDB
:Scheduler
Runtime!
Dependency
:PC
:Planner
84
5. Data Management
♦ Some objects in the models need to be persistent
⬥ Provide clean separation points between subsystems with well-
defined interfaces.
♦ A persistent object can be realized with one of the following
⬥ Data structure
⧫ If the data can be volatile
⬥ Files
⧫ Cheap, simple, permanent storage
⧫ Low level (Read, Write)
⧫ Applications must add code to provide suitable level of abstraction
⬥ Database
⧫ Powerful, easy to port
⧫ Supports multiple writers and readers
85
File or Database?
86
Database Management System
87
Issues To Consider When Selecting a Database
♦ Storage space
⬥ Database require about triple the storage space of actual data
♦ Response time
⬥ Mode databases are I/O or communication bound (distributed databases).
Response time is also affected by CPU time, locking contention and delays
from frequent screen displays
♦ Locking modes
⬥ Pessimistic locking: Lock before accessing object and release when object
access is complete
⬥ Optimistic locking: Reads and writes may freely occur (high concurrency!)
When activity has been completed, database checks if contention has
occurred. If yes, all work has been lost.
♦ Administration
⬥ Large databases require specially trained support staff to set up security
policies, manage the disk space, prepare backups, monitor performance,
adjust tuning.
88
Object-Oriented Databases
89
Relational Databases
90
Data Management Questions
♦ Should the data be distributed?
♦ Should the database be extensible?
♦ How often is the database accessed?
♦ What is the expected request (query) rate? In the worst case?
♦ What is the size of typical and worst case requests?
♦ Do the data need to be archived?
♦ Does the system design try to hide the location of the databases
(location transparency)?
♦ Is there a need for a single interface to access the data?
♦ What is the query format?
♦ Should the database be relational or object-oriented?
91
6. Global Resource Handling
94
Defining Access Control
95
Access Matrix
96
Access Matrix Implementations
98
7. Decide on Software Control
99
Software Control (continued)
!
♦ Decentralized control
⬥ Control resides in several independent objects.
⬥ Possible speedup by mapping the objects on different processors,
increased communication overhead.
⬥ Example: Message based system.
100
Centralized vs. Decentralized Designs
♦ Should you use a centralized or decentralized design?
⬥ Take the sequence diagrams and control objects from the analysis
model
⬥ Check the participation of the control objects in the sequence
diagrams
⧫ If sequence diagram looks more like a fork: Centralized design
⧫ The sequence diagram looks more like a stair: Decentralized design
♦ Centralized Design
⬥ One control object or subsystem ("spider") controls everything
⧫ Pro: Change in the control structure is very easy
⧫ Con: The single conctrol ojbect is a possible performance bottleneck
♦ Decentralized Design
⬥ Not a single object is in control, control is distributed, That means,
there is more than one control object
⧫ Con: The responsibility is spread out
⧫ Pro: Fits nicely into object-oriented development
101
8. Boundary Conditions
102
Example: Administrative Use cases for MyTrip
103
ManageServer Use Case
<<include>>
StartServer
PlanningService
Administrator <<include>>
ManageServer ShutdownServer
<<include>>
ConfigureServer
104
Boundary Condition Questions
♦ 8.1 Initialization
⬥ How does the system start up?
⧫ What data need to be accessed at startup time?
⧫ What services have to registered?
⬥ What does the user interface do at start up time?
⧫ How does it present itself to the user?
♦ 8.2 Termination
⬥ Are single subsystems allowed to terminate?
⬥ Are other subsystems notified if a single subsystem terminates?
⬥ How are local updates communicated to the database?
♦ 8.3 Failure
⬥ How does the system behave when a node or communication link fails? Are
there backup communication links?
⬥ How does the system recover from failure? Is this different from initialization?
105
Modeling Boundary Conditions
106
Object Design
107
Object Design: Closing the Gap
System Problem
Application objects
Solution objects
Custom objects
Off-the-shelf components
Machine
108
Examples of Object Design Activities
109
A More Detailed View 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
110
Detailed View of Object Design Activities (ctd)
Restructuring Optimization
Delaying complex
Realizing associations computations
111
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
112
Outline of Today
♦ Reuse Concepts
♦ The use of inheritance
♦ Implementation vs Interface Inheritance
♦ Delegation
♦ Components
♦ Documenting the Object Design
♦ JavaDoc
113
Reuse Concepts
114
Application domain vs solution domain objects
115
Application Domain vs Solution Domain Objects
Requirements Analysis
Object Design
(Language of Application
(Language of Solution Domain)
Domain)
Incident
Report
Incident
Report
116
Implementation of Application Domain Classes
117
Observation about Modeling of the Real World
♦ [Gamma et al 94]:
♦ Strict modeling of the real world leads to a system that reflects
today’s realities but not necessarily tomorrow’s.
118
The use of inheritance
Inheritance Object
Design
Analysis
activity
Taxonomy Inheritance
for Reuse
120
Taxonomy Example
Mammal
121
Implementation Inheritance
122
Implementation Inheritance vs Interface Inheritance
♦ 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
123
Delegation as alternative to Implementation Inheritance
124
Delegation instead of Implementation Inheritance
♦ Inheritance: Extending a Base class by a new operation or
overwriting an operation.
♦ Delegation: Catching an operation and sending it to another
object.
♦ Which of the following models is better for implementing a
stack? List
+Add() Stack List
+Remove()
Remove()
+Push()
Add()
Stack +Pop()
+Top()
+Push()
+Pop()
+Top()
125
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)
126
Lecture on
Design Patterns
127
Component Selection
♦ 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
128
Reuse...
129
Frameworks
130
Classification of Frameworks
131
Frameworks in the Development Process
132
White-box and Black-Box Frameworks
♦ 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.
133
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…. )
134
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.
135
Example: Framework for Building Web Applications
WebObjects
WebBrowser
WebServer WebObjectsApplication
WOAdaptor
WORequest
WoRequest
StaticHTML Template EOF
RelationalDatabase
136
Documenting the Object Design: The Object Design Document (ODD)
137
Documenting Object Design: ODD Conventions
138
JavaDoc
139
More on JavaDoc
140
Class and Interface Doc Tags
@author name-text
⬥ Creates an “Author” entry.
@version version-text
⬥ Creates a “Version” entry.
@see classname
⬥ Creates a hyperlink “See Also classname”
@since since-text
⬥ 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
⬥ Adds a comment that this method can no longer be used. Convention
is to describe method that serves as replacement
⬥ Example: @deprecated Replaced by setBounds(int, int, int, int).
141
Constructor and Method Doc Tags
♦Can contain @see tag, @since tag, @deprecated as well as:
@param parameter-name description
Adds a parameter to the "Parameters" section. The description may be
continued on the next line.
@return description
Adds a "Returns" section, which contains the description of the return
value.
@exception fully-qualified-class-name description
Adds a "Throws" section, which contains the name of the exception that
may be thrown by the method. The exception is linked to its class
documentation.
@see classname
Adds a hyperlink "See Also" entry to the method.
142
Example of a Class Doc Comment
/**
* A class representing a window on the screen.
* For example:
* <pre>
* Window win = new Window(parent);
* win.show();
* </pre>
*
* @author Sami Shaio
* @version %I%, %G%
* @see java.awt.BaseWindow
* @see java.awt.Button
*/
class Window extends BaseWindow {
...
}
143
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 java.lang.Character#charValue()
*/
public char charAt(int index) {
...
}
144
Example of a Field Doc Comment
145
Example: Specifying a Service in Java
146
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
147
Packaging Heuristics
148