5. oose design new copy

42
Object-Oriented Software Engineering Chapter 5 Object Oriented Design Object-Oriented Systems Development Bahrami © Irwin/ McGraw-Hill System design is the transformation of the analysis model into a system design model.

Transcript of 5. oose design new copy

Page 1: 5. oose design new   copy

Object-Oriented Software Engineering

Chapter 5

Object Oriented Design

Object-Oriented Systems Development Bahrami © Irwin/ McGraw-Hill

System design is the transformation of the

analysis model into a system design model.

Page 2: 5. oose design new   copy

An Overview of Design During system design, developers define the

design goals of the project and decompose the system into smaller subsystems that can be realized

by individual teams.

Developers also select strategies for building the system, such as the hardware/software platform on which the system will run, the persistent data management strategy, the global control flow, the access control policy, and the handling of boundary conditions.

The result of system design is a model that includes a clear description of each of these strategies, a subsystem decomposition, and a UML deployment diagram representing the hardware/software

mapping of the system

Object-Oriented Systems Development Bahrami © Irwin/ McGraw-Hill

Page 3: 5. oose design new   copy

Activities of system Design

Object-Oriented Systems Development Bahrami © Irwin/ McGraw-Hill

Page 4: 5. oose design new   copy

Activities of system DesignIn particular, system design includes:

the definition of design goals

the decomposition of the system into subsystems

the selection of off-the-shelf and legacy components

the mapping of subsystem to hardware

the selection of a persistent data management infrastructure

the selection of an access control policy

the selection of a global control flow mechanism

the handling of boundary conditions

Object-Oriented Systems Development Bahrami © Irwin/ McGraw-Hill

Page 5: 5. oose design new   copy

Activities of system DesignSystem design results in the following products: list of design goals,

describing the qualities of the system that developers shouldoptimize

software architecture, describing the subsystem decomposition in terms of subsystem

responsibilities, dependencies among subsystems, subsystem mapping to hardware,major policy decisions such as control flow, access control, and data storage

The design goals are derived from the nonfunctional requirements

Object-Oriented Systems Development Bahrami © Irwin/ McGraw-Hill

Page 6: 5. oose design new   copy

Activities of System DesignHardware/software mapping: What is the hardware configuration of the system? Which node is responsible for which functionality? How is communication between nodes realized? Which services are realized using existing software components? How are these components encapsulated?

Addressing hardware/software mapping issues often leads to the definition of additional subsystems dedicated to moving data from

one node to another, dealing with concurrency, and reliability issues.

Object-Oriented Systems Development Bahrami © Irwin/ McGraw-Hill

Page 7: 5. oose design new   copy

Activities of System Design Data management:

Which data need to be persistent? Where should persistent data be stored? How are they accessed?

Persistent data represents a bottleneck in the system on many differentfronts: Most functionality in system is concerned with creating ormanipulating persistent data. For this reason, access to the data should be fast and reliable. If retrieving data is slow, the whole system will be slow.

If data corruption is likely, complete system failure is likely. .

Object-Oriented Systems Development Bahrami © Irwin/ McGraw-Hill

Page 8: 5. oose design new   copy

Activities of System DesignAccess control: Access control and security are system-wide issues. The access control policyused to specify who can and cannot access certain data should be the sameacross all subsystems. Who can access which data? Can access control change dynamically? How is access control specified and realized?

Control flow: How does the system sequence operations? Is the system event driven? Can it handle more than one user interaction at a time?The choice of control flow has an impact on the interfaces of subsystems. If an event-driven control flow is selected,

subsystems will provide event handlers.

If threads are selected, subsystems need to guarantee mutual exclusion in critical sections..

Object-Oriented Systems Development Bahrami © Irwin/ McGraw-Hill

Page 9: 5. oose design new   copy

Activities of System DesignBoundary conditions:

How is the system initialized? How is it shut down? How are exceptional cases detected and handled?

System initialization and shutdown often represent the larger part of thecomplexity of a system, especially in a distributed environment.

Initialization, shutdown, and exception handling have an impact on theinterface of all subsystems

Object-Oriented Systems Development Bahrami © Irwin/ McGraw-Hill

Page 10: 5. oose design new   copy

System Design Concepts1. The concept of subsystem and its relationship to classes Subsystems and classes helps to reduce the complexity of the solution

domain. The system is decomposed into simpler parts, called subsystems, which are

made of a number of solution domain classes

Several programming languages (e.g., Java and Modula-2) provideconstructs for modeling subsystems (packages in Java, modules inModula-2).

Developers need to carefully document the subsystemdecomposition as subsystems are usually realized by different teams.

Object-Oriented Systems Development Bahrami © Irwin/ McGraw-Hill

Page 11: 5. oose design new   copy

System Design ConceptsSub System Decomposition

Object-Oriented Systems Development Bahrami © Irwin/ McGraw-Hill

Subsystems are shown as UML packages. Dashed arrows indicate dependencies between subsystems

System Decomposition for accident management system

Page 12: 5. oose design new   copy

System Design Concepts2. Services and subsystem interfaces

A subsystem is characterized by the services it provides to othersubsystems. A service is a set of related operations that share a common

purpose. A subsystem providing a notification service

The set of operations of a subsystem that are available to othersubsystems form the subsystem interface.

The subsystem interface, also referred to as the applicationprogrammer interface (API), includes the name of the operations, their parameters, their types, and their return values.

Object-Oriented Systems Development Bahrami © Irwin/ McGraw-Hill

Page 13: 5. oose design new   copy

System Design Concepts

3. The two properties of subsystems are :– coupling coherence

Coupling measures the dependencies between two subsystems

Coherence measures the dependencies among classes within asubsystem.

Ideal subsystem decomposition should minimize coupling and maximize coherence.

Object-Oriented Systems Development Bahrami © Irwin/ McGraw-Hill

Page 14: 5. oose design new   copy

System Design Concepts3.1 Coupling Coupling is the strength of dependencies between two

subsystems. If two subsystems are loosely coupled,

they are relatively independent, and thus, modifications to one of the subsystems will have little impact on

the other.

If two subsystems are strongly coupled, they are relatively dependent, andmodifications to one subsystem is likely to have impact on the other.

A desirable property of a subsystem decomposition is thatsubsystems are as loosely coupled as possible. This minimizes the impact that errors or future changes have on the

correct operation of the system

Object-Oriented Systems Development Bahrami © Irwin/ McGraw-Hill

Page 15: 5. oose design new   copy

System Design Concepts3.2 Coherence Coherence is the strength of dependencies within a subsystem. If a subsystem contains a number of related objects, and perform

similar tasks, its coherence is high.

If a subsystem contains a number of unrelated objects, its coherence is low.

Subsystem decomposition leads to subsystems with high coherence. Analysis identifies application objects, their relationships, and

attributes and operations. System design identifies subsystems and most important solution

objects. Object design refines and detail both sets of objects and identify any

remaining solution objects needed to complete the system.

Object-Oriented Systems Development Bahrami © Irwin/ McGraw-Hill

Page 16: 5. oose design new   copy

System Design Concepts

The coherence of the RationaleSubsystem and the PlanningSubsystem ishigher than the coherence of the original DecisionSubsystem

Object-Oriented Systems Development Bahrami © Irwin/ McGraw-Hill

Page 17: 5. oose design new   copy

System Design Concepts4. Layering and partitioning

The two techniques for relating subsystems to each other Layering allows a system to be organized as a hierarchy of subsystems,

each providing higher level services to the subsystem above it by usinglower level services from the subsystems below it.

Partitioning organizes subsystems as peers that mutually providedifferent services to each other

The goal of system design is to manage complexity by dividing thesystem into smaller, manageable pieces. This can be done by a divide-and-conquer approach

Each layer can only depend on lower level layers and has no knowledge ofthe layers above it.

In a closed architecture, each layer can only depend on the layersimmediately below it.

In an open architecture, a layer can also access layers at deeper levels

Object-Oriented Systems Development Bahrami © Irwin/ McGraw-Hill

Page 18: 5. oose design new   copy

System Design Concepts A subset from a layered decomposition that includes at least one

subsystem from each layer is called a vertical slice. For example, the subsystems A, B, and E constitute a vertical slice,

whereas the subsystems D and G do not.

Object-Oriented Systems Development Bahrami © Irwin/ McGraw-Hill

Page 19: 5. oose design new   copy

System Design Concepts5. Software architecture A software architecture includes the system decomposition, the

global control flow, error-handling policies and inter subsystemcommunication protocols

1. Repository architecture subsystems access and modify data from a single data structure

called the central repository. Subsystems are relatively independent and interact only through

the central data structure. Control flow can be dictated either by the central repository The repository architecture is typical for database management

systems, such as a payroll system or a bank system

Object-Oriented Systems Development Bahrami © Irwin/ McGraw-Hill

Page 20: 5. oose design new   copy

System Design Concepts

Object-Oriented Systems Development Bahrami © Irwin/ McGraw-Hill

An instance of the repository architecture (UML Class diagram).A modern compiler incrementally generates

a parse tree and a symbol tablethat can be later used by debuggers and syntax editors.

Page 21: 5. oose design new   copy

System Design Concepts

Object-Oriented Systems Development Bahrami © Irwin/ McGraw-Hill

Pros and cons of Repository architectures:

1. Repository architectures are well suited for applications withconstantly changing complex data processing tasks.

2. Once a central repository is well defined, we can easily addnew services in the form of additional subsystems.

3. The main disadvantage of repository systems is that thecentral repository can quickly become a bottleneck, both froma performance aspect and a modifiability aspect

Page 22: 5. oose design new   copy

System Design Concepts

Object-Oriented Systems Development Bahrami © Irwin/ McGraw-Hill

Client/server architecture a subsystem, the server, provides services to instances of other

subsystems called the clients, which are responsible forinteracting with the user.

The request for a service is usually done via a remote procedurecall mechanism or a common object broker (e.g., CORBA or JavaRMI).

Control flow in the clients and the servers is independent exceptfor synchronization to manage requests or to receive results.

Client/server architecture (UML class diagram).

Page 23: 5. oose design new   copy

System Design Concepts

Object-Oriented Systems Development Bahrami © Irwin/ McGraw-Hill

Clients request services from one or more servers. The server has no knowledge of the client. The client/server architecture is a generalization of the repository

architecture. An information system with a central database is an example of a

client/server architecture. The clients are responsible for receiving inputs from the user,

performing range checks, and initiating database transactions onceall necessary data are collected.

The server is then responsible for performing the transaction andguaranteeing the integrity of the data

Page 24: 5. oose design new   copy

UML Deployment diagrams

Object-Oriented Systems Development Bahrami © Irwin/ McGraw-Hill

6. UML deployment diagrams are used to depict the relationshipamong run-time components and hardware nodes. Components are self-contained entities that provide services to

other components or actors. A Web server, for example, is a component that provides

services to Web browsers. A Web browser such as Netscape is a component that provides

services to a user. A distributed system can be composed of many interacting run-

time components

Page 25: 5. oose design new   copy

UML Deployment diagrams

Object-Oriented Systems Development Bahrami © Irwin/ McGraw-Hill

In UML deployment diagrams, nodes are represented by boxes containing component

icons. Dependencies between components are represented by

dashed arrowsAn example of deployment diagram illustrating two Web

browsers accessing a Web

Page 26: 5. oose design new   copy

UML Deployment diagrams

Object-Oriented Systems Development Bahrami © Irwin/ McGraw-Hill

A UML deployment diagram representing the allocation ofcomponents to different nodes and the dependencies amongcomponents.

Web browsers on PCs and Macs can access a WebServer thatprovides information from a Database server.

The Web server in turns accesses data from a database server We can see from the dependency graph that the Web browsers do

not access directly the database at any time. The deployment diagram in Figure focuses on the allocation of

components to nodes and provides a high-level view of eachcomponent.

Components can be refined to include information about theinterfaces they provide and the classes they contain.

Page 27: 5. oose design new   copy

Documenting system design

Object-Oriented Systems Development Bahrami © Irwin/ McGraw-Hill

System design is documented in the System Design Document(SDD).

It describes design goals set by the project, the subsystem decomposition (with UML class diagrams), the hardware/software mapping (with UML deployment

diagrams), the data management, the access control, the control flow mechanisms, and The boundary conditions.

The SDD is used to define interfaces between teams ofdevelopers and as reference when architecture-level decisionsneed to be revisited.

Page 28: 5. oose design new   copy

Documenting system design

Object-Oriented Systems Development Bahrami © Irwin/ McGraw-Hill

Page 29: 5. oose design new   copy

Object design

Object-Oriented Systems Development Bahrami © Irwin/ McGraw-Hill

Object design includes:

service specification, during which we precisely describe each class interface

component selection, during which we identify additional off-the-shelf

components and solution objects object model restructuring,

during which we transform the object design model toimprove its understandability and extensibility

object model optimization, during which we transform the object design model to

address performance criteria such as response time ormemory utilization

Page 30: 5. oose design new   copy

An overview of Object design

Object-Oriented Systems Development Bahrami © Irwin/ McGraw-Hill

During object design,

we refine the analysis and system design models

identify new objects, and

close the gap between the application objects identified

during requirements and off-the-shelf components

selected during system design

As a result, the object design model can be partitioned into sets

of classes such that they can be implemented by individual

developers.

Page 31: 5. oose design new   copy

An overview of Object design

Object-Oriented Systems Development Bahrami © Irwin/ McGraw-Hill

Page 32: 5. oose design new   copy

Object design concepts

Object-Oriented Systems Development Bahrami © Irwin/ McGraw-Hill

The principal object design concepts are:1. application objects versus solution objects2. types, signatures, and visibility3. preconditions, postconditions, and invariants

Application objects versus solution objects Class diagrams can be used to model both the application domain

and the solution domain.

Application objects, also called domain objects, represent conceptsof the domain that the system manipulates.

Solution objects represent support components that do not have acounterpart in the application domain, such as persistent datastores, user interface objects, or middleware.

Page 33: 5. oose design new   copy

Object-Oriented Systems Development Bahrami © Irwin/ McGraw-Hill

Page 34: 5. oose design new   copy

Object design concepts

Object-Oriented Systems Development Bahrami © Irwin/ McGraw-Hill

Types, signatures, and visibility The type of an attribute specifies the range of values the attribute

can take and the operations that can be applied to the attribute The type of the return value is called the signature of the operation The visibility of an attribute or an operation specifies whether it can

be used by other classes Private. A private attribute can be accessed only by the class in

which it is defined. Protected. A protected attribute can be accessed by the class

in which it is defined and on any descendant of the class. Public. A public attribute or operation can be accessed by any

class.

Page 35: 5. oose design new   copy

Object design concept

Object-Oriented Systems Development Bahrami © Irwin/ McGraw-Hill

Contracts: Invariants, preconditions, and postconditions Contracts are constraints on a class that the caller must meet before

using the class as well as constraints that are ensured by the calleewhen used.

Contracts include three types of constraints: An invariant is a predicate that is always true for all instances of a

class. A precondition is a predicate that must be true before an operation

is invoked. Preconditions are associated with a specific operation.Preconditions are used to specify constraints that a caller must meetbefore calling an operation.

A postcondition is a predicate that must be true after an operation isinvoked. Postconditions are associated with a specific operation.Postconditions are used to specify constraints that the object mustensure after the invocation of the operation

Page 36: 5. oose design new   copy

Object design concept

Object-Oriented Systems Development Bahrami © Irwin/ McGraw-Hill

Examples of invariants, preconditions, and postconditions in OCL (UML class diagram).

Page 37: 5. oose design new   copy

Realizing Associations

Object-Oriented Systems Development Bahrami © Irwin/ McGraw-Hill

Associations denote collections of bidirectional links between two ormore objects.

Object-oriented programming languages provide references, in which oneobject stores a handle to another object.

References are unidirectional and take place between two objectsUnidirectional one-to-one associations. The simplest association is a one-to-one association

Realization of a unidirectional one-to-one association Arrow denotes the transformation of the object model

Page 38: 5. oose design new   copy

Realizing Associations

Object-Oriented Systems Development Bahrami © Irwin/ McGraw-Hill

Bidirectional one-to-one associations

Page 39: 5. oose design new   copy

Realizing Associations

Object-Oriented Systems Development Bahrami © Irwin/ McGraw-Hill

Realization of a bidirectional, one-to-many association

Page 40: 5. oose design new   copy

Documenting object design

Object-Oriented Systems Development Bahrami © Irwin/ McGraw-Hill

Object design is documented in the Object Design Document(ODD).

It describes object design trade-offs made by developers, guidelines they followed for subsystem interfaces, The decomposition of subsystems into packages and classes

and the class interfaces.

The ODD is used to exchange interface information among teams and as

a reference during testing. The audience for the ODD includes

system architects, (i.e., the developers who participate in thesystem design)

developers who implement each subsystem, and testers

Page 41: 5. oose design new   copy

Documenting object design

Object-Oriented Systems Development Bahrami © Irwin/ McGraw-Hill

The ODD enables developers to understand the subsystem sufficiently

well that they can use it. a good interface specification which enables other developers

to implement classes concurrently.

An interface specification should satisfy the following criteria[Liskov,1986]:

Restrictiveness. A specification should be precise enough that it excludes

unwanted implementations. Preconditions and postconditions specifying border cases is

one way to achieve restrictive specifications. Generality.

A specification, however, should not restrict itsimplementation.

Page 42: 5. oose design new   copy

Documenting object design

Object-Oriented Systems Development Bahrami © Irwin/ McGraw-Hill

Clarity. A specification should be easily and unambiguously

understandable by developers. it is useless if it is difficult to understand. Certain behaviors are more easily described in natural

language, whereas boundary cases can be described withconstraints and exceptions.