Software Engineering Lecture 18: Object-Oriented Design.

31
Software Engineering Lecture 18: Object-Oriented Design

Transcript of Software Engineering Lecture 18: Object-Oriented Design.

Page 1: Software Engineering Lecture 18: Object-Oriented Design.

Software Engineering

Lecture 18: Object-Oriented Design

Page 2: Software Engineering Lecture 18: Object-Oriented Design.

Today’s Topics Chapter 22, SEPA/5e

(also: Bruegge & Dutoit, Object-Oriented Software Engineering)

Subsystem Design & Architectures Class & Object Design Message Design Responsibility Design

Page 3: Software Engineering Lecture 18: Object-Oriented Design.

OO Design Pyramid

Supports hardware/softwaresystem mapping (packages)

Class definitions, hierarchies,generalizations (modules)

External and internal interfaces(module coupling)

Data structure & algorithm design for attributes & operations (detailed design)

[From SEPA 5/e]

incre

asin

g d

eta

il

Page 4: Software Engineering Lecture 18: Object-Oriented Design.

OOA to OOD[From SEPA 5/e]

Page 5: Software Engineering Lecture 18: Object-Oriented Design.

Subsystem Design System Decomposition

• Layers & Partitioning (packages)

• Cohesion / Coupling

Hardware / Software Mapping• Special Purpose

• Buy/Build

• Resource Allocation

• Connectivity

Page 6: Software Engineering Lecture 18: Object-Oriented Design.

Coupling and Cohesion Goal: Reduce complexity Cohesion measures dependence among classes

• High cohesion: classes in a subsystem perform similar tasks and are related via associations

• Low cohesion: miscellaneous objects, no associations

Page 7: Software Engineering Lecture 18: Object-Oriented Design.

Coupling & Cohesion [2] Coupling measures dependencies between

subsystems• High coupling: Changes to one subsystem have high impact on

the other subsystem

Design should maximize cohesion and minimize coupling:• How can we partition an O-O system to achieve loose

coupling?

Page 8: Software Engineering Lecture 18: Object-Oriented Design.

Partitions and Layers Partitions are independent (weakly-coupled)

subsystems that provide services on the same level of abstraction

Layers are subsystems that provide services to a higher level of abstraction• Layers only depend on lower layers,

have no knowledge of higher layers

Page 9: Software Engineering Lecture 18: Object-Oriented Design.

F:SubsystemE:Subsystem G:Subsystem

D:SubsystemC:SubsystemB:Subsystem

A: Subsystem Layer 1

Layer 2

Layer 3

Layer Example

Decomposition Heuristics• No more than 7+/-2 subsystems

• More subsystems increase coherence but also complexity (more services)

• No more than 5+/-2 layers

Page 10: Software Engineering Lecture 18: Object-Oriented Design.

Subsystem Relationships Layer relationships

• A calls B (runtime)

• A depends on B (compile time)

Partition relationships• Subsystems have mutual but not deep knowledge about each

other

• A calls partition B and B calls A

Page 11: Software Engineering Lecture 18: Object-Oriented Design.

Virtual Machine (Dijkstra, 1965) Systems are layers of virtual machines

VM4

VM3

VM2

VM1C1attropr

C1attropr

C1attropr

C1attropr

C1attropr

C1attropr

C1attropr

C1attropr

Problem

Existing System

Page 12: Software Engineering Lecture 18: Object-Oriented Design.

Virtual Machine An abstraction providing attributes and operations A subsystem connected to higher- and lower-level

virtual machines by provides services for associations

Can implement two types of software architecture: closed and open architectures

Page 13: Software Engineering Lecture 18: Object-Oriented Design.

Closed Architecture (Opaque Layering)

A virtual machine can only call operations from the layer below

Goal: High maintainability

VM4

VM3

VM2

VM1C1

attr

op

C1

attr

op

C1

attr

op

C1

attr

op

C1

attr

op

C1

attr

op

C1

attr

op

C1

attr

op

C1

attr

op

Page 14: Software Engineering Lecture 18: Object-Oriented Design.

Open Architecture(Transparent Layering)

A virtual machine can call operations from any layers

Goal: Runtime efficiency

VM4

VM3

VM2

VM1C1

attr

op

C1

attr

op

C1

attr

op

C1

attr

op

C1

attr

op

C1

attr

op

C1

attr

op

C1

attr

op

C1

attr

op

Page 15: Software Engineering Lecture 18: Object-Oriented Design.

Open vs. Closed Architectures Layered systems are desirable

• hierarchy reduces complexity

Closed architectures more portable Open architectures can be more efficient Prefer closed architecture, unless performance

constraints require an open architecture

Page 16: Software Engineering Lecture 18: Object-Oriented Design.

Hardware / Software Mapping Each layer (subsystem, virtual machine) can

reside on a different hardware / software platform Subsystem decomposition is the basis for multi-

tier architecture• client-server

• web server / application server / database server

• can improve security as well as maintainability

Page 17: Software Engineering Lecture 18: Object-Oriented Design.

Typical 3-Tier Web Architecture

TIER 1:CLIENT

TIER 2:SERVER

TIER 3:BACKEND

Application serveroffloads processing

to tier 3

Page 18: Software Engineering Lecture 18: Object-Oriented Design.

Intershop Architecture

SOURCE: INTERSHOP

Page 19: Software Engineering Lecture 18: Object-Oriented Design.

Selligent Architecture

SOURCE: SELLIGENT

Page 20: Software Engineering Lecture 18: Object-Oriented Design.

KMT Packages &HW/SW Mapping

•Special Purpose•Build (Custom)•Dual P3 rack•TCP/IP Network•C++

Analyzer

•Special Purpose•Build (Custom)•Dual P3 rack •TCP/IP Network•C++

Generator

•Special Purpose•Build (Custom)•Typical PC•TCP/IP Network•JDK 1.2.1

KMT Client

Page 21: Software Engineering Lecture 18: Object-Oriented Design.

Contracts How subsystems interact:

• List requests

• For each request, indicate which operations are needed to implement

• Create a collaboration table orcollaboration graph, depending on the complexity of the contract

Contracts include message format• method call (for objects)

• structured data (other protocols)

Page 22: Software Engineering Lecture 18: Object-Oriented Design.

Collaboration Table[From SEPA 5/e]

Page 23: Software Engineering Lecture 18: Object-Oriented Design.

Types of Contracts[From SEPA 5/e]

public String getResult(String s){};

WORK 18 Remove the engine.

e.g., Java Class API(method signatures)

e.g., string-basedmessage protocol

Page 24: Software Engineering Lecture 18: Object-Oriented Design.

Collaboration Graph[From SEPA 5/e]

Page 25: Software Engineering Lecture 18: Object-Oriented Design.

Object & Class Design Refine the details of classes using:

• Sequence Diagrams

• CRC Cards

Goal: Completed Class Diagram• attributes (fully typed)

• methods (full signatures)

• associations (inheritance, aggregation, etc.)

Page 26: Software Engineering Lecture 18: Object-Oriented Design.

Class-Reponsibility-Collaborator

Abbreviation: CRC Cards Identify and organize class details “Index Cards” approach:

• name, type, characteristicsthe nature of the class

• responsibilitiesfunctions provided by the class

• collaboratorspart-of, knowledge-of, depends-on

Page 27: Software Engineering Lecture 18: Object-Oriented Design.

CRC Index Card[From SEPA 5/e]

Page 28: Software Engineering Lecture 18: Object-Oriented Design.

CRC Formal Review Distribute index cards to reviewers Use cases grouped into categories Read each use case, passing a token from one

person to another when a class is named Holder of the class card reads responsibilities,

which are reviewed by all Cards refined as necessary

Page 29: Software Engineering Lecture 18: Object-Oriented Design.

Class Diagram for KMT Client

Model-ViewDesign Pattern:Separate internalrepresentation fromhow data is displayedto the user

Page 30: Software Engineering Lecture 18: Object-Oriented Design.

Detailed Design Internal data structures and program logic for

each method signature identified in the detailed class diagram

Pseudocode/PDL, flowcharts, etc. Java: Specify algorithm & data structures in

javadoc commentsexample: Collections.sort()

Page 31: Software Engineering Lecture 18: Object-Oriented Design.

Questions?