object-oriented design designing systems using self ... · chapter 12 slide 1 object-oriented...

55
©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 12 Slide 1 Object-oriented Design Designing systems using self- contained objects and object classes

Upload: others

Post on 11-Oct-2020

6 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Object-oriented Design Designing systems using self ... · Chapter 12 Slide 1 Object-oriented Design Designing systems using self-contained objects and object classes ©Ian Sommerville

©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 12 Slide 1

Object-oriented Design

Designing systems using self-contained objects and objectclasses

Page 2: Object-oriented Design Designing systems using self ... · Chapter 12 Slide 1 Object-oriented Design Designing systems using self-contained objects and object classes ©Ian Sommerville

©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 12 Slide 2

Objectives

l To explain how a software design may berepresented as a set of interacting objects thatmanage their own state and operations

l To describe the activities in the object-orienteddesign process

l To introduce various models that describe anobject-oriented design

l To show how the UML may be used to representthese models

Page 3: Object-oriented Design Designing systems using self ... · Chapter 12 Slide 1 Object-oriented Design Designing systems using self-contained objects and object classes ©Ian Sommerville

©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 12 Slide 3

Topics covered

l Objects and object classes

l An object-oriented design process

l Design evolution

Page 4: Object-oriented Design Designing systems using self ... · Chapter 12 Slide 1 Object-oriented Design Designing systems using self-contained objects and object classes ©Ian Sommerville

©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 12 Slide 4

Characteristics of OOD

l Objects are abstractions of real-world or systementities and manage themselves

l Objects are independent and encapsulate state andrepresentation information.

l System functionality is expressed in terms ofobject services

l Shared data areas are eliminated. Objectscommunicate by message passing

l Objects may be distributed and may executesequentially or in parallel

Page 5: Object-oriented Design Designing systems using self ... · Chapter 12 Slide 1 Object-oriented Design Designing systems using self-contained objects and object classes ©Ian Sommerville

©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 12 Slide 5

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 6: Object-oriented Design Designing systems using self ... · Chapter 12 Slide 1 Object-oriented Design Designing systems using self-contained objects and object classes ©Ian Sommerville

©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 12 Slide 6

Advantages of OOD

l Easier maintenance. Objects may beunderstood as stand-alone entities

l Objects are appropriate reusable components

l For some systems, there may be an obviousmapping from real world entities to systemobjects

Page 7: Object-oriented Design Designing systems using self ... · Chapter 12 Slide 1 Object-oriented Design Designing systems using self-contained objects and object classes ©Ian Sommerville

©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 12 Slide 7

Object-oriented development

l Object-oriented analysis, design andprogramming are related but distinct

l OOA is concerned with developing an objectmodel of the application domain

l OOD is concerned with developing an object-oriented system model to implement requirements

l OOP is concerned with realising an OOD usingan OO programming language such as Java orC++

Page 8: Object-oriented Design Designing systems using self ... · Chapter 12 Slide 1 Object-oriented Design Designing systems using self-contained objects and object classes ©Ian Sommerville

©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 12 Slide 8

Objects and object classes

l Objects are entities in a software system whichrepresent instances of real-world and systementities

l Object classes are templates for objects. Theymay be used to create objects

l Object classes may inherit attributes and servicesfrom other object classes

Page 9: Object-oriented Design Designing systems using self ... · Chapter 12 Slide 1 Object-oriented Design Designing systems using self-contained objects and object classes ©Ian Sommerville

©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 12 Slide 9

Objects

An object is an entity which has a state and a defined set ofoperations which operate on that state. The state is represented as aset of object attributes. The operations associated with the objectprovide services to other objects (clients) which request theseservices when some computation is required.

Objects are created according to some object class definition. Anobject class definition serves as a template for objects. It includesdeclarations of all the attributes and services which should beassociated with an object of that class.

Page 10: Object-oriented Design Designing systems using self ... · Chapter 12 Slide 1 Object-oriented Design Designing systems using self-contained objects and object classes ©Ian Sommerville

©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 12 Slide 10

The Unified Modeling Language

l Several different notations for describing object-oriented designs were proposed in the 1980s and1990s

l The Unified Modeling Language is an integrationof these notations

l It describes notations for a number of differentmodels that may be produced during OO analysisand design

l It is now a de facto standard for OO modelling

Page 11: Object-oriented Design Designing systems using self ... · Chapter 12 Slide 1 Object-oriented Design Designing systems using self-contained objects and object classes ©Ian Sommerville

©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 12 Slide 11

Employee object class (UML)Employee

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

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

Page 12: Object-oriented Design Designing systems using self ... · Chapter 12 Slide 1 Object-oriented Design Designing systems using self-contained objects and object classes ©Ian Sommerville

©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 12 Slide 12

Object communication

l Conceptually, objects communicate bymessage passing.

l Messages• The name of the service requested by the calling object.

• Copies of the information required to execute the serviceand the name of a holder for the result of the service.

l In practice, messages are often implementedby procedure calls• Name = procedure name.

• Information = parameter list.

Page 13: Object-oriented Design Designing systems using self ... · Chapter 12 Slide 1 Object-oriented Design Designing systems using self-contained objects and object classes ©Ian Sommerville

©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 12 Slide 13

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) ;

Page 14: Object-oriented Design Designing systems using self ... · Chapter 12 Slide 1 Object-oriented Design Designing systems using self-contained objects and object classes ©Ian Sommerville

©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 12 Slide 14

Generalisation and inheritance

l Objects are members of classes which defineattribute types and operations

l Classes may be arranged in a class hierarchywhere one class (a super-class) is a generalisationof one or more other classes (sub-classes)

l A sub-class inherits the attributes andoperations from its super class and may addnew methods or attributes of its own

l Generalisation in the UML is implemented asinheritance in OO programming languages

Page 15: Object-oriented Design Designing systems using self ... · Chapter 12 Slide 1 Object-oriented Design Designing systems using self-contained objects and object classes ©Ian Sommerville

©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 12 Slide 15

A generalisation hierarchyEmployee

Programmer

projectprogLanguage

Manager

ProjectManager

budgetsControlleddateAppointed

projects

Dept.Manager

StrategicManager

dept responsibilities

Page 16: Object-oriented Design Designing systems using self ... · Chapter 12 Slide 1 Object-oriented Design Designing systems using self-contained objects and object classes ©Ian Sommerville

©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 12 Slide 16

Advantages of inheritance

l It is an abstraction mechanism which may be usedto classify entities

l It is a reuse mechanism at both the design and theprogramming level

l The inheritance graph is a source oforganisational knowledge about domains andsystems

Page 17: Object-oriented Design Designing systems using self ... · Chapter 12 Slide 1 Object-oriented Design Designing systems using self-contained objects and object classes ©Ian Sommerville

©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 12 Slide 17

Problems with inheritance

l Object classes are not self-contained. they cannotbe understood without reference to their super-classes

l Designers have a tendency to reuse theinheritance graph created during analysis. Canlead to significant inefficiency

l The inheritance graphs of analysis, design andimplementation have different functions andshould be separately maintained

Page 18: Object-oriented Design Designing systems using self ... · Chapter 12 Slide 1 Object-oriented Design Designing systems using self-contained objects and object classes ©Ian Sommerville

©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 12 Slide 18

Inheritance and OOD

l There are differing views as to whetherinheritance is fundamental to OOD.• View 1. Identifying the inheritance hierarchy or network is a

fundamental part of object-oriented design. Obviously this canonly be implemented using an OOPL.

• View 2. Inheritance is a useful implementation concept whichallows reuse of attribute and operation definitions. Identifyingan inheritance hierarchy at the design stage places unnecessaryrestrictions on the implementation

l Inheritance introduces complexity and this isundesirable, especially in critical systems

Page 19: Object-oriented Design Designing systems using self ... · Chapter 12 Slide 1 Object-oriented Design Designing systems using self-contained objects and object classes ©Ian Sommerville

©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 12 Slide 19

UML associations

l Objects and object classes participate inrelationships with other objects and object classes

l In the UML, a generalised relationship isindicated by an association

l Associations may be annotated with informationthat describes the association

l Associations are general but may indicate that anattribute of an object is an associated object orthat a method relies on an associated object

Page 20: Object-oriented Design Designing systems using self ... · Chapter 12 Slide 1 Object-oriented Design Designing systems using self-contained objects and object classes ©Ian Sommerville

©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 12 Slide 20

An association model

Employee Department

Manager

is-member-of

is-managed-by

manages

Page 21: Object-oriented Design Designing systems using self ... · Chapter 12 Slide 1 Object-oriented Design Designing systems using self-contained objects and object classes ©Ian Sommerville

©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 12 Slide 21

Concurrent objects

l The nature of objects as self-contained entitiesmake them suitable for concurrentimplementation

l The message-passing model of objectcommunication can be implemented directly ifobjects are running on separate processors in adistributed system

Page 22: Object-oriented Design Designing systems using self ... · Chapter 12 Slide 1 Object-oriented Design Designing systems using self-contained objects and object classes ©Ian Sommerville

©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 12 Slide 22

Servers and active objects

l Servers.• The object is implemented as a parallel process (server)

with entry points corresponding to object operations. If nocalls are made to it, the object suspends itself and waits forfurther requests for service

l Active objects• Objects are implemented as parallel processes and the

internal object state may be changed by the object itself andnot simply by external calls

Page 23: Object-oriented Design Designing systems using self ... · Chapter 12 Slide 1 Object-oriented Design Designing systems using self-contained objects and object classes ©Ian Sommerville

©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 12 Slide 23

Active transponder object

l Active objects may have their attributes modifiedby operations but may also update themautonomously using internal operations

l Transponder object broadcasts an aircraft’sposition. The position may be updated using asatellite positioning system. The objectperiodically update the position by triangulationfrom satellites

Page 24: Object-oriented Design Designing systems using self ... · Chapter 12 Slide 1 Object-oriented Design Designing systems using self-contained objects and object classes ©Ian Sommerville

©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 12 Slide 24

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

Page 25: Object-oriented Design Designing systems using self ... · Chapter 12 Slide 1 Object-oriented Design Designing systems using self-contained objects and object classes ©Ian Sommerville

©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 12 Slide 25

Java threads

l Threads in Java are a simple construct forimplementing concurrent objects

l Threads must include a method called run() andthis is started up by the Java run-time system

l Active objects typically include an infinite loopso that they are always carrying out thecomputation

Page 26: Object-oriented Design Designing systems using self ... · Chapter 12 Slide 1 Object-oriented Design Designing systems using self-contained objects and object classes ©Ian Sommerville

©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 12 Slide 26

An object-oriented design process

l Define the context and modes of use of thesystem

l Design the system architecture

l Identify the principal system objects

l Develop design models

l Specify object interfaces

Page 27: Object-oriented Design Designing systems using self ... · Chapter 12 Slide 1 Object-oriented Design Designing systems using self-contained objects and object classes ©Ian Sommerville

©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 12 Slide 27

Weather system description

A weather data collection system is required to generate weather maps on aregular 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 arequest from that machine.

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

Page 28: Object-oriented Design Designing systems using self ... · Chapter 12 Slide 1 Object-oriented Design Designing systems using self-contained objects and object classes ©Ian Sommerville

©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 12 Slide 28

Weather station description

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

When a command is issued to transmit the weather data, theweather station processes and summarises the collected data. Thesummarised data is transmitted to the mapping computer when arequest is received.

Page 29: Object-oriented Design Designing systems using self ... · Chapter 12 Slide 1 Object-oriented Design Designing systems using self-contained objects and object classes ©Ian Sommerville

©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 12 Slide 29

Layered architecture

«subsystem»Data collection

«subsystem»Data processing

«subsystem»Data archiving

«subsystem»Data display

Data collection layer where objectsare concerned with acquiring datafrom remote sources

Data processing layer where objectsare concerned with checking andintegrating the collected data

Data archiving layer where objectsare concerned with storing the data for future processing

Data display layer where objects areconcerned with preparing andpresenting the data in a human-readable form

Page 30: Object-oriented Design Designing systems using self ... · Chapter 12 Slide 1 Object-oriented Design Designing systems using self-contained objects and object classes ©Ian Sommerville

©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 12 Slide 30

System context and models of use

l Develop an understanding of the relationshipsbetween the software being designed and itsexternal environment

l System context• A static model that describes other systems in the environment.

Use a subsystem model to show other systems. Following slideshows the systems around the weather station system.

l Model of system use• A dynamic model that describes how the system interacts with

its environment. Use use-cases to show interactions

Page 31: Object-oriented Design Designing systems using self ... · Chapter 12 Slide 1 Object-oriented Design Designing systems using self-contained objects and object classes ©Ian Sommerville

©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 12 Slide 31

Subsystems in the weather mapping system

«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 32: Object-oriented Design Designing systems using self ... · Chapter 12 Slide 1 Object-oriented Design Designing systems using self-contained objects and object classes ©Ian Sommerville

©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 12 Slide 32

Use-cases for the weather station

Startup

Shutdown

Report

Calibrate

Test

Page 33: Object-oriented Design Designing systems using self ... · Chapter 12 Slide 1 Object-oriented Design Designing systems using self-contained objects and object classes ©Ian Sommerville

©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 12 Slide 33

Use-case descriptionSystem 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 totalrainfall and the wind direction as sampled at 5 minute intervals.

Stimulus The weather data collection system establishes a modem link with theweather station 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 infuture.

Page 34: Object-oriented Design Designing systems using self ... · Chapter 12 Slide 1 Object-oriented Design Designing systems using self-contained objects and object classes ©Ian Sommerville

©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 12 Slide 34

Architectural design

l Once interactions between the system and itsenvironment have been understood, you use thisinformation for designing the system architecture

l Layered architecture is appropriate for theweather station• Interface layer for handling communications

• Data collection layer for managing instruments

• Instruments layer for collecting data

l There should be no more than 7 entities in anarchitectural model

Page 35: Object-oriented Design Designing systems using self ... · Chapter 12 Slide 1 Object-oriented Design Designing systems using self-contained objects and object classes ©Ian Sommerville

©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 12 Slide 35

Weather station architecture

«subsystem»Data collection

«subsystem»Instruments

«subsystem»Interface

Weather station

Manages allexternal

communications

Collects andsummarisesweather data

Package ofinstruments for raw

data collections

Page 36: Object-oriented Design Designing systems using self ... · Chapter 12 Slide 1 Object-oriented Design Designing systems using self-contained objects and object classes ©Ian Sommerville

©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 12 Slide 36

Object identification

l Identifying objects (or object classes) is the mostdifficult part ofobject oriented design

l There is no 'magic formula' for objectidentification. It relies on the skill, experienceand domain knowledge of system designers

l Object identification is an iterative process. Youare unlikely to get it right first time

Page 37: Object-oriented Design Designing systems using self ... · Chapter 12 Slide 1 Object-oriented Design Designing systems using self-contained objects and object classes ©Ian Sommerville

©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 12 Slide 37

Approaches to identification

l Use a grammatical approach based on a naturallanguage description of the system (used in Hoodmethod)

l Base the identification on tangible things in theapplication domain

l Use a behavioural approach and identify objectsbased on what participates in what behaviour

l Use a scenario-based analysis. The objects,attributes and methods in each scenario areidentified

Page 38: Object-oriented Design Designing systems using self ... · Chapter 12 Slide 1 Object-oriented Design Designing systems using self-contained objects and object classes ©Ian Sommerville

©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 12 Slide 38

Weather station object classes

l Ground thermometer, Anemometer, Barometer• Application domain objects that are ‘hardware’ objects related

to the instruments in the system

l Weather station• The basic interface of the weather station to its environment. It

therefore reflects the interactions identified in the use-casemodel

l Weather data• Encapsulates the summarised data from the instruments

Page 39: Object-oriented Design Designing systems using self ... · Chapter 12 Slide 1 Object-oriented Design Designing systems using self-contained objects and object classes ©Ian Sommerville

©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 12 Slide 39

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 40: Object-oriented Design Designing systems using self ... · Chapter 12 Slide 1 Object-oriented Design Designing systems using self-contained objects and object classes ©Ian Sommerville

©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 12 Slide 40

Further objects and object refinement

l Use domain knowledge to identify more objectsand operations• Weather stations should have a unique identifier

• Weather stations are remotely situated so instrument failureshave to be reported automatically. Therefore attributes andoperations for self-checking are required

l Active or passive objects• In this case, objects are passive and collect data on request

rather than autonomously. This introduces flexibility at theexpense of controller processing time

Page 41: Object-oriented Design Designing systems using self ... · Chapter 12 Slide 1 Object-oriented Design Designing systems using self-contained objects and object classes ©Ian Sommerville

©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 12 Slide 41

Design models

l Design models show the objects and objectclasses and relationships between these entities

l Static models describe the static structure of thesystem in terms of object classes and relationships

l Dynamic models describe the dynamicinteractions between objects.

Page 42: Object-oriented Design Designing systems using self ... · Chapter 12 Slide 1 Object-oriented Design Designing systems using self-contained objects and object classes ©Ian Sommerville

©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 12 Slide 42

Examples of design models

l Sub-system models that show logical groupingsof objects into coherent subsystems

l Sequence models that show the sequence ofobject interactions

l State machine models that show how individualobjects change their state in response to events

l Other models include use-case models,aggregation models, generalisation models,etc.

Page 43: Object-oriented Design Designing systems using self ... · Chapter 12 Slide 1 Object-oriented Design Designing systems using self-contained objects and object classes ©Ian Sommerville

©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 12 Slide 43

Subsystem models

l Shows how the design is organised into logicallyrelated groups of objects

l In the UML, these are shown using packages - anencapsulation construct. This is a logical model.The actual organisation of objects in the systemmay be different.

Page 44: Object-oriented Design Designing systems using self ... · Chapter 12 Slide 1 Object-oriented Design Designing systems using self-contained objects and object classes ©Ian Sommerville

©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 12 Slide 44

Weather station subsystems«subsystem»

Interface

CommsController

WeatherStation

«subsystem»Data collection

«subsystem»Instruments

Air thermometer

WeatherData

Ground thermometer

Anemometer

WindVane

RainGauge

InstrumentStatus

Barometer

Page 45: Object-oriented Design Designing systems using self ... · Chapter 12 Slide 1 Object-oriented Design Designing systems using self-contained objects and object classes ©Ian Sommerville

©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 12 Slide 45

Sequence models

l Sequence models show the sequence of objectinteractions that take place• Objects are arranged horizontally across the top

• Time is represented vertically so models are read top to bottom

• Interactions are represented by labelled arrows, Different stylesof arrow represent different types of interaction

• A thin rectangle in an object lifeline represents the time whenthe object is the controlling object in the system

Page 46: Object-oriented Design Designing systems using self ... · Chapter 12 Slide 1 Object-oriented Design Designing systems using self-contained objects and object classes ©Ian Sommerville

©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 12 Slide 46

Data collection sequence:CommsController

request (report)

acknowledge ()report ()

summarise ()

reply (report)

acknowledge ()

send (report)

:WeatherStation :WeatherData

Page 47: Object-oriented Design Designing systems using self ... · Chapter 12 Slide 1 Object-oriented Design Designing systems using self-contained objects and object classes ©Ian Sommerville

©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 12 Slide 47

Statecharts

l Show how objects respond to different servicerequests and the state transitions triggered bythese requests• If object state is Shutdown then it responds to a Startup()

message

• In the waiting state the object is waiting for further messages

• If reportWeather () then system moves to summarising state

• If calibrate () the system moves to a calibrating state

• A collecting state is entered when a clock signal is received

Page 48: Object-oriented Design Designing systems using self ... · Chapter 12 Slide 1 Object-oriented Design Designing systems using self-contained objects and object classes ©Ian Sommerville

©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 12 Slide 48

Weather station state diagram

Shutdown Waiting Testing

Transmitting

Collecting

Summarising

Calibrating

transmission done

calibrate ()

test ()startup ()

shutdown ()

calibration OK

test complete

weather summarycomplete

clock collectiondone

Operation

reportWeather ()

Page 49: Object-oriented Design Designing systems using self ... · Chapter 12 Slide 1 Object-oriented Design Designing systems using self-contained objects and object classes ©Ian Sommerville

©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 12 Slide 49

Object interface specification

l Object interfaces have to be specified so that theobjects and other components can be designed inparallel

l Designers should avoid designing the interfacerepresentation but should hide this in the objectitself

l Objects may have several interfaces which areviewpoints on the methods provided

l The UML uses class diagrams for interfacespecification but Java may also be used

Page 50: Object-oriented Design Designing systems using self ... · Chapter 12 Slide 1 Object-oriented Design Designing systems using self-contained objects and object classes ©Ian Sommerville

©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 12 Slide 50

Weather station interfaceinterface 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 51: Object-oriented Design Designing systems using self ... · Chapter 12 Slide 1 Object-oriented Design Designing systems using self-contained objects and object classes ©Ian Sommerville

©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 12 Slide 51

Design evolution

l Hiding information inside objects means thatchanges made to an object do not affect otherobjects in an unpredictable way

l Assume pollution monitoring facilities are to beadded to weather stations. These sample theair and compute the amount of differentpollutants in the atmosphere

l Pollution readings are transmitted with weatherdata

Page 52: Object-oriented Design Designing systems using self ... · Chapter 12 Slide 1 Object-oriented Design Designing systems using self-contained objects and object classes ©Ian Sommerville

©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 12 Slide 52

Changes required

l Add an object class called ‘Air quality’ as part ofWeatherStation

l Add an operation reportAirQuality toWeatherStation. Modify the control software tocollect pollution readings

l Add objects representing pollution monitoringinstruments

Page 53: Object-oriented Design Designing systems using self ... · Chapter 12 Slide 1 Object-oriented Design Designing systems using self-contained objects and object classes ©Ian Sommerville

©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 12 Slide 53

Pollution monitoring

NODatasmokeDatabenzeneData

collect ()summarise ()

Air qualityidentifier

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

WeatherStation

Pollution monitoring instruments

NOmeter SmokeMeter

BenzeneMeter

Page 54: Object-oriented Design Designing systems using self ... · Chapter 12 Slide 1 Object-oriented Design Designing systems using self-contained objects and object classes ©Ian Sommerville

©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 12 Slide 54

l OOD is an approach to design so that designcomponents have their own private state andoperations

l Objects should have constructor and inspectionoperations. They provide services to other objects

l Objects may be implemented sequentially orconcurrently

l The Unified Modeling Language providesdifferent notations for defining different objectmodels

Key points

Page 55: Object-oriented Design Designing systems using self ... · Chapter 12 Slide 1 Object-oriented Design Designing systems using self-contained objects and object classes ©Ian Sommerville

©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 12 Slide 55

Key points

l A range of different models may be producedduring an object-oriented design process. Theseinclude static and dynamic system models

l Object interfaces should be defined preciselyusing e.g. a programming language like Java

l Object-oriented design simplifies systemevolution