Top Banner
©Ian Sommerville 2000 Software Engineering. Chapter 14 Slide 1 Chapter 14 Object-Oriented Design
74

Chapter 14 · The history of OO Development as ... Chapter 14 Slide 20 The Unified Modeling Language ... Chapter 14 Slide 29 Inheritance and OOD

Jul 16, 2018

Download

Documents

vukhuong
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Chapter 14 · The history of OO Development as ... Chapter 14 Slide 20 The Unified Modeling Language ... Chapter 14 Slide 29 Inheritance and OOD

©Ian Sommerville 2000 Software Engineering. Chapter 14 Slide 1

Chapter 14

Object-Oriented Design

Page 2: Chapter 14 · The history of OO Development as ... Chapter 14 Slide 20 The Unified Modeling Language ... Chapter 14 Slide 29 Inheritance and OOD

©Ian Sommerville 2000 Software Engineering. Chapter 14 Slide 2

Objectives

● To explain how a software design may be represented as a set of interacting objects that encapsulate their own state and operations.

● To describe (and illustrate) the activitiesin the object-oriented design process.

(cont’d)

Page 3: Chapter 14 · The history of OO Development as ... Chapter 14 Slide 20 The Unified Modeling Language ... Chapter 14 Slide 29 Inheritance and OOD

©Ian Sommerville 2000 Software Engineering. Chapter 14 Slide 3

Objectives (cont’d)

● To introduce various models used to describe an object-oriented design

● To show how the UML may be used to represent these models

Page 4: Chapter 14 · The history of OO Development as ... Chapter 14 Slide 20 The Unified Modeling Language ... Chapter 14 Slide 29 Inheritance and OOD

©Ian Sommerville 2000 Software Engineering. Chapter 14 Slide 4

Topics covered

● Characteristics of OOD

● History of OOD as reflected by Sommerville

● Objects and object classes

● Generalization and inheritance

● An object-oriented design process (Weather Station example)

● Design evolution

Page 5: Chapter 14 · The history of OO Development as ... Chapter 14 Slide 20 The Unified Modeling Language ... Chapter 14 Slide 29 Inheritance and OOD

©Ian Sommerville 2000 Software Engineering. Chapter 14 Slide 5

Characteristics of OOD

● Allows designers to think in terms of interacting objects that maintain their own state and provide operations on that state instead of a set of functions operating on shared data.

● Objects hide information about the represen-tation of state and hence limit access to it.

● Objects may be distributed and may work sequentially or in parallel.

Page 6: Chapter 14 · The history of OO Development as ... Chapter 14 Slide 20 The Unified Modeling Language ... Chapter 14 Slide 29 Inheritance and OOD

©Ian Sommerville 2000 Software Engineering. Chapter 14 Slide 6

A design strategy based on “information hiding”…

Another way to think about “information hiding”:

Potentially changeable design decisions are isolated (i.e., “hidden”) to minimize the impact of change.

- David Parnas

(Is there any connection between information hiding and AOSD?)

Page 7: Chapter 14 · The history of OO Development as ... Chapter 14 Slide 20 The Unified Modeling Language ... Chapter 14 Slide 29 Inheritance and OOD

©Ian Sommerville 2000 Software Engineering. Chapter 14 Slide 7

Interacting objects

state o3

o3:C3

state o4

o4: C4

state o1

o1: C1

state o6

o6: C1

state o5

o5:C5

state o2

o2: C3

ops1() ops3 () ops4 ()

ops3 () ops1 () ops5 ()

Page 8: Chapter 14 · The history of OO Development as ... Chapter 14 Slide 20 The Unified Modeling Language ... Chapter 14 Slide 29 Inheritance and OOD

©Ian Sommerville 2000 Software Engineering. Chapter 14 Slide 8

Advantages of OOD

● Easier maintenance. Objects may be understood as stand-alone entities (and ripple effect is reduced).

● Objects are appropriate reusablecomponents.

● For some systems, there is an obvious mapping from real world entities to system objects.

Page 9: Chapter 14 · The history of OO Development as ... Chapter 14 Slide 20 The Unified Modeling Language ... Chapter 14 Slide 29 Inheritance and OOD

©Ian Sommerville 2000 Software Engineering. Chapter 14 Slide 9

Object-oriented development

● OO Analysis : concerned with developing an object model of the application domain.

● OO Design : concerned with developing an object-oriented system model to implement requirements

● OO Programming : concerned with realising an OOD using an OO pro-gramming language such as Java or C++.

Page 10: Chapter 14 · The history of OO Development as ... Chapter 14 Slide 20 The Unified Modeling Language ... Chapter 14 Slide 29 Inheritance and OOD

©Ian Sommerville 2000 Software Engineering. Chapter 14 Slide 10

The history of OO Development as reflected by Sommerville’s text

● 1st Edition (1982): No mention of OO design!

● 2nd Edition (1985): …it has been sug-gested that a better design methodology is OO design… To place such comments in perspective, many large systems have been built using top-down design. Few large systems have been built using an object-oriented approach.

Page 11: Chapter 14 · The history of OO Development as ... Chapter 14 Slide 20 The Unified Modeling Language ... Chapter 14 Slide 29 Inheritance and OOD

©Ian Sommerville 2000 Software Engineering. Chapter 14 Slide 11

The history of OO Development as reflected by Sommerville’s text

● 3rd Edition (1989): It is only within the past few years that an alternative mode of decomposition, OO design, has been recognized as of value.

● 4th Edition (1992): OO methods are still relatively immature and are changing rapidly so are not nearly as widely used as methods based on functional decomposition. They will become more widely used as they mature…

Page 12: Chapter 14 · The history of OO Development as ... Chapter 14 Slide 20 The Unified Modeling Language ... Chapter 14 Slide 29 Inheritance and OOD

©Ian Sommerville 2000 Software Engineering. Chapter 14 Slide 12

The history of OO Development as reflected by Sommerville’s text

● 5th Edition (1995): Until relatively recently, the most commonly used software design strategy involved decomposing the design into functional components with system state information held in a shared data area…It is only since the late 1980’s that…OO design has been widely adopted.

Page 13: Chapter 14 · The history of OO Development as ... Chapter 14 Slide 20 The Unified Modeling Language ... Chapter 14 Slide 29 Inheritance and OOD

©Ian Sommerville 2000 Software Engineering. Chapter 14 Slide 13

The history of OO Development as reflected by Sommerville’s text

● 6th Edition(2001): An OO approach to the whole (of) software development is now commonly used…

Coverage of functional design is now included in the new chapter on legacy systems.

Page 14: Chapter 14 · The history of OO Development as ... Chapter 14 Slide 20 The Unified Modeling Language ... Chapter 14 Slide 29 Inheritance and OOD

©Ian Sommerville 2000 Software Engineering. Chapter 14 Slide 14

The history of OO Development as reflected by Sommerville’s text

● 7th Edition (2004): Chapter on legacy systems deleted.

Although many software developers consider function-oriented design to be an outdated approach, OO development may not offer significant advantages (in some) situations. An interesting challenge…is to ensure that function-oriented and OO systems can work together.

Page 15: Chapter 14 · The history of OO Development as ... Chapter 14 Slide 20 The Unified Modeling Language ... Chapter 14 Slide 29 Inheritance and OOD

©Ian Sommerville 2000 Software Engineering. Chapter 14 Slide 15

The history of OO Development as reflected by Sommerville’s text

● 8th Edition (2007): Chapter on Aspect-Oriented Software Development added.

In most large systems...implementing a change to a requirement may involve understanding and changing many components... AOSD is an emerging approach...intended to address this problem. Aspects are used alongside other abstractions such as objects and methods. (AOSD) support separating concerns into independent elements...

Page 16: Chapter 14 · The history of OO Development as ... Chapter 14 Slide 20 The Unified Modeling Language ... Chapter 14 Slide 29 Inheritance and OOD

©Ian Sommerville 2000 Software Engineering. Chapter 14 Slide 16

Should we still be placing an emphasis on OO Design?

● Extensive up-front design can be criticized because the extensive analysis and design effort is not well suited to incremental development and delivery.

● Agile methods have been developed to address this problem.

Page 17: Chapter 14 · The history of OO Development as ... Chapter 14 Slide 20 The Unified Modeling Language ... Chapter 14 Slide 29 Inheritance and OOD

©Ian Sommerville 2000 Software Engineering. Chapter 14 Slide 17

Should we still be placing an emphasis on OO Design? (cont’d)

● Sommerville's view: extensive, “heavy-weight” design is unnecessary for small and medium-sized systems. But for large systems, particularly critical systems, it is essential to ensure that teams working on different parts of the system are properly coordinated.

Page 18: Chapter 14 · The history of OO Development as ... Chapter 14 Slide 20 The Unified Modeling Language ... Chapter 14 Slide 29 Inheritance and OOD

©Ian Sommerville 2000 Software Engineering. Chapter 14 Slide 18

Objects and object classes

● Objects are entities with state and a defined set of operations on that state.

§ State is represented as a set of object attributes.

§ Operations provide services to other objectswhen requested.

Page 19: Chapter 14 · The history of OO Development as ... Chapter 14 Slide 20 The Unified Modeling Language ... Chapter 14 Slide 29 Inheritance and OOD

©Ian Sommerville 2000 Software Engineering. Chapter 14 Slide 19

Objects and object classes (cont’d)

● Object classes are templates for objects.

§ An object class definition includes declarations of all attributes and operationsassociated with an object of that class.

§ They may inherit attributes and services from other object classes.

Page 20: Chapter 14 · The history of OO Development as ... Chapter 14 Slide 20 The Unified Modeling Language ... Chapter 14 Slide 29 Inheritance and OOD

©Ian Sommerville 2000 Software Engineering. Chapter 14 Slide 20

The Unified Modeling Language

● Several different notations for OOD were proposed in the 1980s and 1990s. (Booch, Rumbaugh, Jacobson, Coad & Yourdon, Wirfs, …)

● UML is an integration of these notations.

● It describes a number of different models that may be produced during OO analysis and design (user view, structural view, behavioural view, implementation view, …)

● The de facto standard for OO modelling.

Page 21: Chapter 14 · The history of OO Development as ... Chapter 14 Slide 20 The Unified Modeling Language ... Chapter 14 Slide 29 Inheritance and OOD

©Ian Sommerville 2000 Software Engineering. Chapter 14 Slide 21

Employee object class (UML)Employee

name: stringaddress: stringdateOfBirth: DateemployeeNo: integersocialSecurityNo: stringdepartment: Deptmanager: Employeesalary: integerstatus: {current, left, retired}taxCode: integer. . .

join ()leave ()retire ()changeDetails ()

Object attributes

Services to other objects

Page 22: Chapter 14 · The history of OO Development as ... Chapter 14 Slide 20 The Unified Modeling Language ... Chapter 14 Slide 29 Inheritance and OOD

©Ian Sommerville 2000 Software Engineering. Chapter 14 Slide 22

Object communication

● Conceptually, objects communicate by message passing.

● Messages include:§ The name of the service requested,

§ A copy of the information required to carry out the service, and

§ the name of a holder for the result of the service.

● In practice, messages are often imple-mented by procedure calls

Page 23: Chapter 14 · The history of OO Development as ... Chapter 14 Slide 20 The Unified Modeling Language ... Chapter 14 Slide 29 Inheritance and OOD

©Ian Sommerville 2000 Software Engineering. Chapter 14 Slide 23

Message examples

// Call a method associated with a buffer // object that returns the next value // in the buffer

v = circularBuffer.Get () ;

// Call the method associated with a// thermostat object that sets the // temperature to be maintained

thermostat.setTemp (20) ;

Info required

Name of service

Holderfor result

(cf. XML text messages in service-based systems)

Page 24: Chapter 14 · The history of OO Development as ... Chapter 14 Slide 20 The Unified Modeling Language ... Chapter 14 Slide 29 Inheritance and OOD

©Ian Sommerville 2000 Software Engineering. Chapter 14 Slide 24

Generalization and inheritance

● Objects are members of classes which define attribute types and operations.

● Classes may be arranged in a hierarchy where one class (a super-class) is a generalization of one or more other classes (sub-classes)

Page 25: Chapter 14 · The history of OO Development as ... Chapter 14 Slide 20 The Unified Modeling Language ... Chapter 14 Slide 29 Inheritance and OOD

©Ian Sommerville 2000 Software Engineering. Chapter 14 Slide 25

Generalization and inheritance

● A sub-class inherits the attributes and operations from its super class and may add new methods or attributes of its own.

Page 26: Chapter 14 · The history of OO Development as ... Chapter 14 Slide 20 The Unified Modeling Language ... Chapter 14 Slide 29 Inheritance and OOD

©Ian Sommerville 2000 Software Engineering. Chapter 14 Slide 26

A UML generalisation hierarchy

Employee

Programmer

projectprogLanguage

Manager

ProjectManager

budgetsControlleddateAppointed

projects

Dept.Manager

StrategicManager

dept responsibilities

Definition on slide 19

Page 27: Chapter 14 · The history of OO Development as ... Chapter 14 Slide 20 The Unified Modeling Language ... Chapter 14 Slide 29 Inheritance and OOD

©Ian Sommerville 2000 Software Engineering. Chapter 14 Slide 27

Advantages of inheritance

● It is an abstraction mechanism which may be used to classify entities.

● It is a reuse mechanism at both the design and the programming level.

● The inheritance graph is a source oforganizational knowledge about domains and systems. (OO Analysis)

Page 28: Chapter 14 · The history of OO Development as ... Chapter 14 Slide 20 The Unified Modeling Language ... Chapter 14 Slide 29 Inheritance and OOD

©Ian Sommerville 2000 Software Engineering. Chapter 14 Slide 28

Problems with inheritance

● Object classes are not self-contained (i.e., they cannot be understood without reference to their super-classes).

● Designers have a tendency to reuse the inheritance graph created during analysis. (Inheritance graphs of analysis, design and implementation have different functions.)

Due to inherited attributes/ops

Discipline/education problem?

Page 29: Chapter 14 · The history of OO Development as ... Chapter 14 Slide 20 The Unified Modeling Language ... Chapter 14 Slide 29 Inheritance and OOD

©Ian Sommerville 2000 Software Engineering. Chapter 14 Slide 29

Inheritance and OOD

● Inheritance is a useful implementationconcept which allows reuse of attribute and operation definitions.

● Some feel that identifying an inheritance hierarchy or network is also a funda-mental part of object-oriented design.(Obviously, this can only be implemented directly u sing an OOPL.)

(cont’d)

Page 30: Chapter 14 · The history of OO Development as ... Chapter 14 Slide 20 The Unified Modeling Language ... Chapter 14 Slide 29 Inheritance and OOD

©Ian Sommerville 2000 Software Engineering. Chapter 14 Slide 30

Inheritance and OOD (cont’d)

● Others feel this places unnecessary restrictions on the implementation.*

● Inheritance introduces complexity and this is undesirable, especially in critical systems. (where design transparency is of utmost importance)

* This appears to be Sommerville’s view

Page 31: Chapter 14 · The history of OO Development as ... Chapter 14 Slide 20 The Unified Modeling Language ... Chapter 14 Slide 29 Inheritance and OOD

©Ian Sommerville 2000 Software Engineering. Chapter 14 Slide 31

UML associations

● Objects and object classes participate in various types of relationships with other objects and object classes.

● In the UML, a generalized relationship is indicated by an association.

(cont’d)

Page 32: Chapter 14 · The history of OO Development as ... Chapter 14 Slide 20 The Unified Modeling Language ... Chapter 14 Slide 29 Inheritance and OOD

©Ian Sommerville 2000 Software Engineering. Chapter 14 Slide 32

UML associations (cont’d)

● Associations may be annotated with information that describes their nature.

● Associations can be used to indicate that an attribute of an object is an associated object or that a method relies on an associated object.

(semantics)

Page 33: Chapter 14 · The history of OO Development as ... Chapter 14 Slide 20 The Unified Modeling Language ... Chapter 14 Slide 29 Inheritance and OOD

©Ian Sommerville 2000 Software Engineering. Chapter 14 Slide 33

An association model

Employee Department

Manager

is-member-of

is-managed-by

manages

annotations

Page 34: Chapter 14 · The history of OO Development as ... Chapter 14 Slide 20 The Unified Modeling Language ... Chapter 14 Slide 29 Inheritance and OOD

©Ian Sommerville 2000 Software Engineering. Chapter 14 Slide 34

Concurrent objects

● The nature of objects as self-contained entities make them well suited for con-current implementation.

● The message-passing model of object communication can be implemented directly if objects are running on separate processors in a distributed system. (as opposed to using procedure calls)

(e.g., as XML text messages in service-based systems)

Page 35: Chapter 14 · The history of OO Development as ... Chapter 14 Slide 20 The Unified Modeling Language ... Chapter 14 Slide 29 Inheritance and OOD

©Ian Sommerville 2000 Software Engineering. Chapter 14 Slide 35

Concurrent object implementation: servers and active objects

● Servers (Passive objects): entry points correspond to object operations. If no calls are made to it, the object suspends itself and waits for further requests for service.

● Active objects: internal object state may be changed by the object itself and not simply by external calls.

Page 36: Chapter 14 · The history of OO Development as ... Chapter 14 Slide 20 The Unified Modeling Language ... Chapter 14 Slide 29 Inheritance and OOD

©Ian Sommerville 2000 Software Engineering. Chapter 14 Slide 36

Example: an active transponder object

● A transponder object broadcasts an aircraft’s position. (on demand)

● The object periodically updates the position by triangulation from satellites. (autonomously)

Page 37: Chapter 14 · The history of OO Development as ... Chapter 14 Slide 20 The Unified Modeling Language ... Chapter 14 Slide 29 Inheritance and OOD

©Ian Sommerville 2000 Software Engineering. Chapter 14 Slide 37

An active transponder objectclass Transponder extends Thread {

Position currentPosition ;Coords c1, c2 ;Satellite sat1, sat2 ;Navigator theNavigator ;

public Position givePosition (){

return currentPosition ;}

public void run (){

while (true){

c1 = sat1.position () ;c2 = sat2.position () ;currentPosition = theNavigator.compute (c1, c2) ;

}

}

} //Transponder

ON DEMAND

IN

BACKGROUND

Java-based interface description

Page 38: Chapter 14 · The history of OO Development as ... Chapter 14 Slide 20 The Unified Modeling Language ... Chapter 14 Slide 29 Inheritance and OOD

©Ian Sommerville 2000 Software Engineering. Chapter 14 Slide 38

Active object implementation : Java threads, Ada tasks, etc.

● Threads in Java are a simple construct for implementing concurrent objects.

● Threads must include a method called run() and this is started up by the Java run-time system.

● Active objects typically include an infinite loop so that they are always carrying out the computation.

Page 39: Chapter 14 · The history of OO Development as ... Chapter 14 Slide 20 The Unified Modeling Language ... Chapter 14 Slide 29 Inheritance and OOD

©Ian Sommerville 2000 Software Engineering. Chapter 14 Slide 39

An object-oriented design process (an iterative, boot-strapping process)

Page 40: Chapter 14 · The history of OO Development as ... Chapter 14 Slide 20 The Unified Modeling Language ... Chapter 14 Slide 29 Inheritance and OOD

©Ian Sommerville 2000 Software Engineering. Chapter 14 Slide 40

An object-oriented design process (an iterative, boot-strapping process)

1. Define the context and modes of use of the system.

2. Design the system architecture.

3. Identify the principal system objects.

4. Develop design models (static and dynamic).

5. Specify object interfaces.

Page 41: Chapter 14 · The history of OO Development as ... Chapter 14 Slide 20 The Unified Modeling Language ... Chapter 14 Slide 29 Inheritance and OOD

©Ian Sommerville 2000 Software Engineering. Chapter 14 Slide 41

Weather system description

A weather data collection system is required to generate weather maps on a regular basis using data collected from remote, unattended weather stationsand other data sources such as weather observers, balloons and satellites. Weather stations transmit their data to the area computer in response to a request from that machine.

Page 42: Chapter 14 · The history of OO Development as ... Chapter 14 Slide 20 The Unified Modeling Language ... Chapter 14 Slide 29 Inheritance and OOD

©Ian Sommerville 2000 Software Engineering. Chapter 14 Slide 42

Weather system description

The area computer validates the collected data and integrates it with the data from different sources. The integrated data is archived and, using data from this archive and a digitized map database, a set of local weather maps is created. Maps may be printed for distribution on a special-purpose map printer or may be displayed in a number of different formats.

Page 43: Chapter 14 · The history of OO Development as ... Chapter 14 Slide 20 The Unified Modeling Language ... Chapter 14 Slide 29 Inheritance and OOD

©Ian Sommerville 2000 Software Engineering. Chapter 14 Slide 43

Weather station description

A weather station is a package of software controlled instrumentswhich collects data, performs some data processingand transmits this datafor further processing. The instruments include air and ground thermometers, an anemometer, a wind vane, a barometerand a rain gauge. Data is collected every five minutes.

Page 44: Chapter 14 · The history of OO Development as ... Chapter 14 Slide 20 The Unified Modeling Language ... Chapter 14 Slide 29 Inheritance and OOD

©Ian Sommerville 2000 Software Engineering. Chapter 14 Slide 44

Weather station description

When a command is issued to transmit the weather data, the weather station processes and summarises the collected data. The summarised data is transmitted to the mapping computer when a request is received.

Page 45: Chapter 14 · The history of OO Development as ... Chapter 14 Slide 20 The Unified Modeling Language ... Chapter 14 Slide 29 Inheritance and OOD

©Ian Sommerville 2000 Software Engineering. Chapter 14 Slide 45

1. Define system context and modes of use

● Goal: develop an understanding of the relationships between the software being designed and its external environment.

● System context: a static model that describes other systems in the environ-ment.

● The context of the weather station is illustrated below using UML packages .

Page 46: Chapter 14 · The history of OO Development as ... Chapter 14 Slide 20 The Unified Modeling Language ... Chapter 14 Slide 29 Inheritance and OOD

©Ian Sommerville 2000 Software Engineering. Chapter 14 Slide 46

Context of weather station«subsystem»Data collection

«subsystem»Data processing

«subsystem»Data archiving

«subsystem»Data display

Weatherstation

Satellite

Comms

Balloon

Observer

Datachecking

Dataintegration

Map store Data store

Datastorage

Map

Userinterface

Mapdisplay

Mapprinter

Page 47: Chapter 14 · The history of OO Development as ... Chapter 14 Slide 20 The Unified Modeling Language ... Chapter 14 Slide 29 Inheritance and OOD

©Ian Sommerville 2000 Software Engineering. Chapter 14 Slide 47

1. Define system context and modes of use (cont.)

● Modes of system use: a dynamic model that describes how the system will interact with its environment.

● Modes of weather station use are illustrated below using a UML use-case model .

Page 48: Chapter 14 · The history of OO Development as ... Chapter 14 Slide 20 The Unified Modeling Language ... Chapter 14 Slide 29 Inheritance and OOD

©Ian Sommerville 2000 Software Engineering. Chapter 14 Slide 48

Use-cases for the weather station

Startup

Shutdown

Report

Calibrate

Test

External entity (weather data collection sys)

Possible interactions

Page 49: Chapter 14 · The history of OO Development as ... Chapter 14 Slide 20 The Unified Modeling Language ... Chapter 14 Slide 29 Inheritance and OOD

©Ian Sommerville 2000 Software Engineering. Chapter 14 Slide 49

Use-case description

System Weather stationUse-case ReportActors Weather data collection system, Weather stationData The weather station sends a summary of the weather data that has been

collected from the instruments in the collection period to the weather datacollection system. The data sent are the maximum minimum and averageground and air temperatures, the maximum, minimum and average airpressures, the maximum, minimum and average wind speeds, the total rainfalland the wind direction as sampled at 5 minute intervals.

Stimulus The weather data collection system establishes a modem link with the weatherstation and requests transmission of the data.

Response The summarised data is sent to the weather data collection systemComments Weather stations are usually asked to report once per hour but this frequency

may differ from one station to the other and may be modified in future.

basis for “information hiding”

Page 50: Chapter 14 · The history of OO Development as ... Chapter 14 Slide 20 The Unified Modeling Language ... Chapter 14 Slide 29 Inheritance and OOD

©Ian Sommerville 2000 Software Engineering. Chapter 14 Slide 50

2. Design system architecture

● A layered architecture is appropriate for the weather station:

§ Interface layer for handling communications

§ Data collection layer for collecting and summarizing weather data

§ Instruments layer for encapsulating instruments used to collect raw data

● Rule of Thumb: There should be no more than 7 entities in an architectural model. (See Miller, "The Magical Number Seven, Plus or Minus Tw o,“WOR. )

Page 51: Chapter 14 · The history of OO Development as ... Chapter 14 Slide 20 The Unified Modeling Language ... Chapter 14 Slide 29 Inheritance and OOD

©Ian Sommerville 2000 Software Engineering. Chapter 14 Slide 51

Weather station architecture

«subsystem»Data collection

«subsystem»Instruments

«subsystem»Interface

Weather station

Manages allexternal

communications

Collects andsummarisesweather data

Package ofinstruments for raw

data collections

UML “nested packages” UML annotations

Page 52: Chapter 14 · The history of OO Development as ... Chapter 14 Slide 20 The Unified Modeling Language ... Chapter 14 Slide 29 Inheritance and OOD

©Ian Sommerville 2000 Software Engineering. Chapter 14 Slide 52

3. Identify principal system objects

● Identifying objects (or object classes) is the most difficult part of OO design.

● There is no “magic formula” – it relies on the skill, experience, and domain knowledge of system designers

● An iterative process – you are unlikely to get it right the first time.

Page 53: Chapter 14 · The history of OO Development as ... Chapter 14 Slide 20 The Unified Modeling Language ... Chapter 14 Slide 29 Inheritance and OOD

©Ian Sommerville 2000 Software Engineering. Chapter 14 Slide 53

Approaches to object identification

● Use a grammatical approach based on a natural language description of the system (Abbott’s heuristic).

● Associate objects with tangible things in the application domain (e.g. devices).

● Use a behavioural approach: identify objects based on what participates in what behaviour.

Page 54: Chapter 14 · The history of OO Development as ... Chapter 14 Slide 20 The Unified Modeling Language ... Chapter 14 Slide 29 Inheritance and OOD

©Ian Sommerville 2000 Software Engineering. Chapter 14 Slide 54

Approaches to object identification (cont.)

● Use scenario-based analysis. The objects, attributes and methods in each scenario are identified.

● Use an information-hiding based approach.* Identify potentially change-able design decisions and isolate these in separate objects.

* “Bonus” approach! (No extra charge.)

Page 55: Chapter 14 · The history of OO Development as ... Chapter 14 Slide 20 The Unified Modeling Language ... Chapter 14 Slide 29 Inheritance and OOD

©Ian Sommerville 2000 Software Engineering. Chapter 14 Slide 55

Weather station object classes

● Weather station – interface of the weather station to its environment. It reflects interactions identified in the use-case model.

● Weather data – encapsulates summarised data from the instruments.

● Ground thermometer, Anemometer, Barometer – application domain “hardware”objects* related to the instruments in the system.

* hardware-controlling SOFTWARE

Page 56: Chapter 14 · The history of OO Development as ... Chapter 14 Slide 20 The Unified Modeling Language ... Chapter 14 Slide 29 Inheritance and OOD

©Ian Sommerville 2000 Software Engineering. Chapter 14 Slide 56

Weather station object classes

identifier

reportWeather ()calibrate (instruments)test ()startup (instruments)shutdown (instruments)

WeatherStation

test ()calibrate ()

Groundthermometer

temperature

Anemometer

windSpeedwindDirection

test ()

Barometer

pressureheight

test ()calibrate ()

WeatherData

airTemperaturesgroundTemperatureswindSpeedswindDirectionspressuresrainfall

collect ()summarise ()

Page 57: Chapter 14 · The history of OO Development as ... Chapter 14 Slide 20 The Unified Modeling Language ... Chapter 14 Slide 29 Inheritance and OOD

©Ian Sommerville 2000 Software Engineering. Chapter 14 Slide 57

Other objects and object refinement

● Use domain knowledge to identify more objects, operations, and attributes.

§ Weather stations should have a unique identifier.

§ Weather stations are remotely situated so instrument failures have to be reported automatically. Therefore, attributes and operations for self-checking are required.

Page 58: Chapter 14 · The history of OO Development as ... Chapter 14 Slide 20 The Unified Modeling Language ... Chapter 14 Slide 29 Inheritance and OOD

©Ian Sommerville 2000 Software Engineering. Chapter 14 Slide 58

Other objects and object refinement (cont.)

● Active or passive objects?

§ Instrument objects are passive and collect data on request rather than autonomously. This introduces flexibility (how?)* at the expense of controller processing time.

§ Are any active objects required?

* Hint: consider potentially changeable design deci sions

Page 59: Chapter 14 · The history of OO Development as ... Chapter 14 Slide 20 The Unified Modeling Language ... Chapter 14 Slide 29 Inheritance and OOD

©Ian Sommerville 2000 Software Engineering. Chapter 14 Slide 59

4. Develop design models

● Design models show the relationships among objects and object classes.

§ Static models describe the static structure of the system in terms of object and object class relationships.

§ Dynamic models describe the dynamic interactions among objects.

Page 60: Chapter 14 · The history of OO Development as ... Chapter 14 Slide 20 The Unified Modeling Language ... Chapter 14 Slide 29 Inheritance and OOD

©Ian Sommerville 2000 Software Engineering. Chapter 14 Slide 60

Examples of design models

● Sub-system models show logical groupings of objects into coherent sub-systems. (static)

● Sequence models show the sequence of object interactions associated with system uses. (dynamic)

(cont’d)

Page 61: Chapter 14 · The history of OO Development as ... Chapter 14 Slide 20 The Unified Modeling Language ... Chapter 14 Slide 29 Inheritance and OOD

©Ian Sommerville 2000 Software Engineering. Chapter 14 Slide 61

Examples of design models (cont’d)

● State machine models show how indi-vidual objects change their state in re-sponse to events. (dynamic)

● Other models include use-case models, aggregation models, generalisation (inheritance) models, etc.

Page 62: Chapter 14 · The history of OO Development as ... Chapter 14 Slide 20 The Unified Modeling Language ... Chapter 14 Slide 29 Inheritance and OOD

©Ian Sommerville 2000 Software Engineering. Chapter 14 Slide 62

Subsystem models

● In the UML, these are shown using packages, an encapsulation construct.

● This is a logical model – the actual organization of objects in the system as implemented may be different.

Page 63: Chapter 14 · The history of OO Development as ... Chapter 14 Slide 20 The Unified Modeling Language ... Chapter 14 Slide 29 Inheritance and OOD

©Ian Sommerville 2000 Software Engineering. Chapter 14 Slide 63

Weather station subsystems«subsystem»

Interface

CommsController

WeatherStation

«subsystem»Data collection

«subsystem»Instruments

Air thermometer

WeatherData

Ground thermometer

Anemometer

WindVane

RainGauge

InstrumentStatus

Barometer

Annotations go here

Active object

Page 64: Chapter 14 · The history of OO Development as ... Chapter 14 Slide 20 The Unified Modeling Language ... Chapter 14 Slide 29 Inheritance and OOD

©Ian Sommerville 2000 Software Engineering. Chapter 14 Slide 64

Sequence models

● Objects are arranged horizontally across the top.

● Time is represented vertically; models are read top to bottom.

● Interactions are represented by labelled arrows – different styles of arrows represent different types of interaction.

● A thin rectangle in an object lifeline represents the time when the object is the controlling object in the system.

Page 65: Chapter 14 · The history of OO Development as ... Chapter 14 Slide 20 The Unified Modeling Language ... Chapter 14 Slide 29 Inheritance and OOD

©Ian Sommerville 2000 Software Engineering. Chapter 14 Slide 65

Data collection sequence:CommsController

request (report)

acknowledge ()report ()

summarise ()

reply (report)

acknowledge ()

send (report)

:WeatherStation :WeatherData

Return of controlNo reply expected

area computer

Page 66: Chapter 14 · The history of OO Development as ... Chapter 14 Slide 20 The Unified Modeling Language ... Chapter 14 Slide 29 Inheritance and OOD

©Ian Sommerville 2000 Software Engineering. Chapter 14 Slide 66

Weather station state machine model

Shutdown Waiting Testing

Transmitting

Collecting

Summarising

Calibrating

transmission done

calibrate ()

test ()startup ()

shutdown ()

calibration OK

test complete

weather summarycomplete

clock collectiondone

Operation

reportWeather ()

Page 67: Chapter 14 · The history of OO Development as ... Chapter 14 Slide 20 The Unified Modeling Language ... Chapter 14 Slide 29 Inheritance and OOD

©Ian Sommerville 2000 Software Engineering. Chapter 14 Slide 67

5. Object interface specification

● Designers should avoid revealing data representation information in their interface design. (operations access and update all data)

● Objects may have several logical interfaces which are viewpoints on the methods provided. (supported directly in Java)

● The UML uses class diagrams for interface specification but pseudocode may also be used.

Page 68: Chapter 14 · The history of OO Development as ... Chapter 14 Slide 20 The Unified Modeling Language ... Chapter 14 Slide 29 Inheritance and OOD

©Ian Sommerville 2000 Software Engineering. Chapter 14 Slide 68

Weather station interface (Java-based)

interface WeatherStation {

public void WeatherStation () ;

public void startup () ;public void startup (Instrument i) ;

public void shutdown () ;public void shutdown (Instrument i) ;

public void reportWeather ( ) ;

public void test () ;public void test ( Instrument i ) ;

public void calibrate ( Instrument i) ;

public int getID () ;

} //WeatherStation

Page 69: Chapter 14 · The history of OO Development as ... Chapter 14 Slide 20 The Unified Modeling Language ... Chapter 14 Slide 29 Inheritance and OOD

©Ian Sommerville 2000 Software Engineering. Chapter 14 Slide 69

Design evolution

● Hiding information in objects means that changes made to an object need not affect other objects in an unpredictable way.

● Assume pollution monitoring facilities are to be added to weather stations.

● Pollution readings are transmitted with weather data.

Page 70: Chapter 14 · The history of OO Development as ... Chapter 14 Slide 20 The Unified Modeling Language ... Chapter 14 Slide 29 Inheritance and OOD

©Ian Sommerville 2000 Software Engineering. Chapter 14 Slide 70

Changes required

● Add an object class called “Air quality” as part of WeatherStation.

● Add an operation reportAirQuality to WeatherStation. Modify the control software to collect pollution readings.

● Add objects representing pollution monitoring instruments.

…and that’s all.

Page 71: Chapter 14 · The history of OO Development as ... Chapter 14 Slide 20 The Unified Modeling Language ... Chapter 14 Slide 29 Inheritance and OOD

©Ian Sommerville 2000 Software Engineering. Chapter 14 Slide 71

NODatasmokeDatabenzeneData

collect ()summarise ()

Air qualityidentifier

reportWeather ()reportAirQuality ()calibrate (instruments)test ()startup (instruments)shutdown (instruments)

WeatherStation

Pollution monitoring instruments

NOmeter SmokeMeter

BenzeneMeter

Pollution monitoring

Page 72: Chapter 14 · The history of OO Development as ... Chapter 14 Slide 20 The Unified Modeling Language ... Chapter 14 Slide 29 Inheritance and OOD

©Ian Sommerville 2000 Software Engineering. Chapter 14 Slide 72

● OOD results in design components with their own private state and operations.

● Objects should have constructor and inspection operations. They provide services to other objects.

● Objects may be implemented sequentially or concurrently.

● The Unified Modeling Language provides different notations for defining different object models.

Key points

as do algebraic specs

(cont’d)

Page 73: Chapter 14 · The history of OO Development as ... Chapter 14 Slide 20 The Unified Modeling Language ... Chapter 14 Slide 29 Inheritance and OOD

©Ian Sommerville 2000 Software Engineering. Chapter 14 Slide 73

Key points (cont’d)

● A range of different models may be produced during an object-oriented design process. These include static and dynamic system models (See the OMG website

for sources.)

● Object interfaces should be defined precisely.

● Object-oriented design simplifies system evolution.

Page 74: Chapter 14 · The history of OO Development as ... Chapter 14 Slide 20 The Unified Modeling Language ... Chapter 14 Slide 29 Inheritance and OOD

©Ian Sommerville 2000 Software Engineering. Chapter 14 Slide 74

Chapter 14

Object-Oriented Design