59
© 2001 Franz Kurfess Object-oriented Design 1 CPE/CSC 205: Software Engineering I Dr. Franz J. Kurfess Computer Science Department Cal Poly

© 2001 Franz Kurfess Object-oriented Design 1 CPE/CSC 205: Software Engineering I Dr. Franz J. Kurfess Computer Science Department Cal Poly

Embed Size (px)

Citation preview

Page 1: © 2001 Franz Kurfess Object-oriented Design 1 CPE/CSC 205: Software Engineering I Dr. Franz J. Kurfess Computer Science Department Cal Poly

© 2001 Franz Kurfess Object-oriented Design 1

CPE/CSC 205: Software Engineering I

CPE/CSC 205: Software Engineering I

Dr. Franz J. Kurfess

Computer Science Department

Cal Poly

Page 2: © 2001 Franz Kurfess Object-oriented Design 1 CPE/CSC 205: Software Engineering I Dr. Franz J. Kurfess Computer Science Department Cal Poly

© 2001 Franz Kurfess Object-oriented Design 2

Course OverviewCourse Overview Introduction Requirements Engineering

Requirements Elicitation Requirements Management

Project Management System Design Methods

and Notations

Design Models and Object-Oriented Design

Design Analysis and Formal Specification

Design Analysis and Verification

Conclusions

Page 3: © 2001 Franz Kurfess Object-oriented Design 1 CPE/CSC 205: Software Engineering I Dr. Franz J. Kurfess Computer Science Department Cal Poly

© 2001 Franz Kurfess Object-oriented Design 3

Chapter OverviewDesign Models and

Object-oriented Design

Chapter OverviewDesign Models and

Object-oriented Design Motivation Objectives Objects and Object Classes Object-oriented Design

Process

Design Evolution Important Concepts and

Terms Chapter Summary

Page 4: © 2001 Franz Kurfess Object-oriented Design 1 CPE/CSC 205: Software Engineering I Dr. Franz J. Kurfess Computer Science Department Cal Poly

© 2001 Franz Kurfess Object-oriented Design 8

Objectives

to explain how a software design may be represented as a set of interacting objects that manage their own state and operations

to describe the activities in the object-oriented design process

to introduce various models that describe an object-oriented design

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

[Sommerville 01]

Page 5: © 2001 Franz Kurfess Object-oriented Design 1 CPE/CSC 205: Software Engineering I Dr. Franz J. Kurfess Computer Science Department Cal Poly

© 2001 Franz Kurfess Object-oriented Design 10

Object-oriented Design (OOD)

Designing systems using self-contained objects and object classes

[Sommerville 01]

Page 6: © 2001 Franz Kurfess Object-oriented Design 1 CPE/CSC 205: Software Engineering I Dr. Franz J. Kurfess Computer Science Department Cal Poly

© 2001 Franz Kurfess Object-oriented Design 11

Characteristics of OODobjects

abstractions of real-world or system entities manage themselves independent encapsulate state and representation information communicate by message passing

no shared data areas

may be distributed may execute sequentially or in parallel

system functionality is expressed in terms of object services

[Sommerville 01]

Page 7: © 2001 Franz Kurfess Object-oriented Design 1 CPE/CSC 205: Software Engineering I Dr. Franz J. Kurfess Computer Science Department Cal Poly

© 2001 Franz Kurfess Object-oriented Design 12

Interacting Objectsstate o3o3:C3state o4o4: C4state o1o1: C1state o6o6: C1state o5o5:C5state o2o2: C3ops1()ops3 ()ops4 ()ops3 ()ops1 ()ops5 ()

[Sommerville 01]

Page 8: © 2001 Franz Kurfess Object-oriented Design 1 CPE/CSC 205: Software Engineering I Dr. Franz J. Kurfess Computer Science Department Cal Poly

© 2001 Franz Kurfess Object-oriented Design 13

Advantages of OOD

easier maintenance objects may be understood as stand-alone entities

reusability objects are appropriate reusable components

there may be an obvious mapping from real world entities to system objects

[Sommerville 01]

Page 9: © 2001 Franz Kurfess Object-oriented Design 1 CPE/CSC 205: Software Engineering I Dr. Franz J. Kurfess Computer Science Department Cal Poly

© 2001 Franz Kurfess Object-oriented Design 14

Object-oriented Development

object-oriented analysis (OOA), design (OOD) and programming (OOP) are related but distinct OOA is concerned with developing an object model of the

application domain OOD is concerned with developing an object-oriented

system model to implement requirements OOP is concerned with realizing an OOD

using an OO programming language such as Java or C++

[Sommerville 01]

Page 10: © 2001 Franz Kurfess Object-oriented Design 1 CPE/CSC 205: Software Engineering I Dr. Franz J. Kurfess Computer Science Department Cal Poly

© 2001 Franz Kurfess Object-oriented Design 15

Objects and Object Classes

objects are entities in a software system they represent instances of real-world and system entities

object classes are templates for objects they may be used to create objects

object classes may inherit attributes and services from other object classes

[Sommerville 01]

Page 11: © 2001 Franz Kurfess Object-oriented Design 1 CPE/CSC 205: Software Engineering I Dr. Franz J. Kurfess Computer Science Department Cal Poly

© 2001 Franz Kurfess Object-oriented Design 16[Sommerville 01]

ObjectsObjects

an object is an entity which has a state and a defined set of operations which operate on that state the state is represented as a set of object attributes the operations associated with the object provide services

to other objects (clients) which request these services when some computation is required

objects are created according to some object class definition an object class definition serves as a template for objects it includes declarations of all the attributes and services

which should be associated with an object of that class

Page 12: © 2001 Franz Kurfess Object-oriented Design 1 CPE/CSC 205: Software Engineering I Dr. Franz J. Kurfess Computer Science Department Cal Poly

© 2001 Franz Kurfess Object-oriented Design 17

Unified Modeling Language (UML)Unified Modeling Language (UML)

several different notations for describing object-oriented designs were proposed in the 1980s and 1990s

the Unified Modeling Language is an integration of these notations

it describes notations for a number of different models that may be produced during OO analysis and design

it is now a de facto standard for OO modeling

[Sommerville 01]

Page 13: © 2001 Franz Kurfess Object-oriented Design 1 CPE/CSC 205: Software Engineering I Dr. Franz J. Kurfess Computer Science Department Cal Poly

© 2001 Franz Kurfess Object-oriented Design 18

Employee Object Class (UML)Employee Object Class (UML)Employeename: stringaddress: stringdateOfBirth: DateemployeeNo: integersocialSecurityNo: stringdepartment: Deptmanager: Employeesalary: integerstatus: {current, left, retired}taxCode: integer. . .join ()leave ()retire ()changeDetails ()[Sommerville 01]

name

attributes

operations

Page 14: © 2001 Franz Kurfess Object-oriented Design 1 CPE/CSC 205: Software Engineering I Dr. Franz J. Kurfess Computer Science Department Cal Poly

© 2001 Franz Kurfess Object-oriented Design 19

Object Communication

conceptually, objects communicate by message passing

messages the name of the service requested by the calling object copies of the information required to execute the service

and the name of a holder for the result of the service

in practice, messages are often implemented by procedure calls name = procedure name information = parameter list

[Sommerville 01]

Page 15: © 2001 Franz Kurfess Object-oriented Design 1 CPE/CSC 205: Software Engineering I Dr. Franz J. Kurfess Computer Science Department Cal Poly

© 2001 Franz Kurfess Object-oriented Design 20

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

[Sommerville 01]

Page 16: © 2001 Franz Kurfess Object-oriented Design 1 CPE/CSC 205: Software Engineering I Dr. Franz J. Kurfess Computer Science Department Cal Poly

© 2001 Franz Kurfess Object-oriented Design 21

Generalization and Inheritance

objects are members of classes with defined attribute types and operations

classes may be arranged in a class hierarchy one class (a super-class) is a generalization of one or more

other classes (sub-classes)

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

generalization in UML implemented as inheritance in OO programming languages

[Sommerville 01]

Page 17: © 2001 Franz Kurfess Object-oriented Design 1 CPE/CSC 205: Software Engineering I Dr. Franz J. Kurfess Computer Science Department Cal Poly

© 2001 Franz Kurfess Object-oriented Design 22

A Generalization HierarchyEmployeeProgrammerprojectprogLanguageManagerProjectManagerbudgetsControlleddateAppointedprojectsDept.ManagerStrategicManagerdept responsibilities

[Sommerville 01]

root class

subclass

generalization

Page 18: © 2001 Franz Kurfess Object-oriented Design 1 CPE/CSC 205: Software Engineering I Dr. Franz J. Kurfess Computer Science Department Cal Poly

© 2001 Franz Kurfess Object-oriented Design 23

Advantages of Inheritance

abstraction mechanism used to classify entitiesreuse mechanism at both design and programming

levelthe inheritance graph is a source of organizational

knowledge about domains and systems

[Sommerville 01]

Page 19: © 2001 Franz Kurfess Object-oriented Design 1 CPE/CSC 205: Software Engineering I Dr. Franz J. Kurfess Computer Science Department Cal Poly

© 2001 Franz Kurfess Object-oriented Design 24

Problems With Inheritanceobject classes are not self-contained

they cannot be understood without reference to their super-classes

makes re-use more difficult they cannot be used as pre-fabricated building blocks to realize

complex systems

designers have a tendency to reuse the inheritance graph created during analysis can lead to significant inefficiency

the inheritance graphs of analysis, design and implementation have different functions should be separately maintained

[Sommerville 01]

Page 20: © 2001 Franz Kurfess Object-oriented Design 1 CPE/CSC 205: Software Engineering I Dr. Franz J. Kurfess Computer Science Department Cal Poly

© 2001 Franz Kurfess Object-oriented Design 25

Inheritance and OODdiffering views as to whether inheritance is fundamental

to OOD view 1

identifying the inheritance hierarchy or network is a fundamental part of object-oriented design

obviously this can only be implemented using an OOPL

view 2 inheritance is a useful implementation concept which allows reuse of

attribute and operation definitions identifying an inheritance hierarchy at the design stage places

unnecessary restrictions on the implementation

inheritance introduces complexity this can be undesirable, especially in critical systems

[Sommerville 01]

Page 21: © 2001 Franz Kurfess Object-oriented Design 1 CPE/CSC 205: Software Engineering I Dr. Franz J. Kurfess Computer Science Department Cal Poly

© 2001 Franz Kurfess Object-oriented Design 26

UML AssociationsUML Associations

objects and object classes participate in relationships with other objects and object classes

associations in UML indicate a general relationship may be annotated with information that describes the

association associations are general

may indicate that an attribute of an object is an associated object or that a method relies on an associated object

[Sommerville 01]

Page 22: © 2001 Franz Kurfess Object-oriented Design 1 CPE/CSC 205: Software Engineering I Dr. Franz J. Kurfess Computer Science Department Cal Poly

© 2001 Franz Kurfess Object-oriented Design 27

An Association ModelEmployee DepartmentManageris-member-ofis-managed-bymanages[Sommerville 01]

associations labels

classes

Page 23: © 2001 Franz Kurfess Object-oriented Design 1 CPE/CSC 205: Software Engineering I Dr. Franz J. Kurfess Computer Science Department Cal Poly

© 2001 Franz Kurfess Object-oriented Design 28

Concurrent objects

objects are self-contained entities makes them suitable for concurrent implementation

message-passing model object communication can be implemented directly if

objects are running on separate processors in a distributed system

[Sommerville 01]

Page 24: © 2001 Franz Kurfess Object-oriented Design 1 CPE/CSC 205: Software Engineering I Dr. Franz J. Kurfess Computer Science Department Cal Poly

© 2001 Franz Kurfess Object-oriented Design 29

Servers and Active Objects

server an object is implemented as a parallel process (or thread)

with entry points corresponding to object operations if no calls are made to it, the object suspends itself and

waits for further service requests

active objects objects are implemented as parallel processes the internal state may be changed by the object itself

not only by external calls

[Sommerville 01]

Page 25: © 2001 Franz Kurfess Object-oriented Design 1 CPE/CSC 205: Software Engineering I Dr. Franz J. Kurfess Computer Science Department Cal Poly

© 2001 Franz Kurfess Object-oriented Design 30

Example: Active Transponder Object

active object may have its attributes modified by operations may also update them autonomously using internal

operations

transponder object broadcasts an aircraft’s position the position may be updated using a satellite positioning

system the object periodically updates the position by triangulation

from satellites

[Sommerville 01]

Page 26: © 2001 Franz Kurfess Object-oriented Design 1 CPE/CSC 205: Software Engineering I Dr. Franz J. Kurfess Computer Science Department Cal Poly

© 2001 Franz Kurfess Object-oriented Design 31

Example: Active Transponder Object

class 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

[Sommerville 01]

Page 27: © 2001 Franz Kurfess Object-oriented Design 1 CPE/CSC 205: Software Engineering I Dr. Franz J. Kurfess Computer Science Department Cal Poly

© 2001 Franz Kurfess Object-oriented Design 32

Java ThreadsJava Threads

threads in Java a simple construct for implementing concurrent objects must include a method called run()

this is started up by the Java run-time system

active objects typically include an infinite loop they are always ready to carry out the computation

[Sommerville 01]

Page 28: © 2001 Franz Kurfess Object-oriented Design 1 CPE/CSC 205: Software Engineering I Dr. Franz J. Kurfess Computer Science Department Cal Poly

© 2001 Franz Kurfess Object-oriented Design 33

An Object-oriented Design ProcessAn Object-oriented Design Process

define the context and modes of use of the systemdesign the system architectureidentify the principal system objectsdevelop design modelsspecify object interfaces

[Sommerville 01]

Page 29: © 2001 Franz Kurfess Object-oriented Design 1 CPE/CSC 205: Software Engineering I Dr. Franz J. Kurfess Computer Science Department Cal Poly

© 2001 Franz Kurfess Object-oriented Design 34

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 stations and 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.

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.

[Sommerville 01]

Page 30: © 2001 Franz Kurfess Object-oriented Design 1 CPE/CSC 205: Software Engineering I Dr. Franz J. Kurfess Computer Science Department Cal Poly

© 2001 Franz Kurfess Object-oriented Design 35

Weather Station Description

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

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.

[Sommerville 01]

Page 31: © 2001 Franz Kurfess Object-oriented Design 1 CPE/CSC 205: Software Engineering I Dr. Franz J. Kurfess Computer Science Department Cal Poly

© 2001 Franz Kurfess Object-oriented Design 36

Layered ArchitectureLayered Architecture

«subsystem»Data collection«subsystem»Data processing«subsystem»Data archiving«subsystem»Data displayData collection layer where objectsare concerned with acquiring datafrom remote sourcesData processing layer where objectsare concerned with checking andintegrating the collected dataData archiving layer where objectsare concerned with storing the data for future processingData display layer where objects areconcerned with preparing andpresenting the data in a human-readable form

[Sommerville 01]

Page 32: © 2001 Franz Kurfess Object-oriented Design 1 CPE/CSC 205: Software Engineering I Dr. Franz J. Kurfess Computer Science Department Cal Poly

© 2001 Franz Kurfess Object-oriented Design 37

System Context and Models of UseSystem Context and Models of Use

develop an understanding of the relationships between the software being designed and its external environment

system context static model that describes other systems in the

environment

model of system use a dynamic model that describes how the system interacts

with its environment use use-cases to show interactions

[Sommerville 01]

Page 33: © 2001 Franz Kurfess Object-oriented Design 1 CPE/CSC 205: Software Engineering I Dr. Franz J. Kurfess Computer Science Department Cal Poly

© 2001 Franz Kurfess Object-oriented Design 38

Context Weather StationContext Weather Station

Balloon

[Sommerville 01]

Satellite

Communications

Weather Station

Observer

Page 34: © 2001 Franz Kurfess Object-oriented Design 1 CPE/CSC 205: Software Engineering I Dr. Franz J. Kurfess Computer Science Department Cal Poly

© 2001 Franz Kurfess Object-oriented Design 39

Use Cases Weather StationUse Cases Weather StationStartupShutdownReportCalibrateTest[Sommerville 01]

Page 35: © 2001 Franz Kurfess Object-oriented Design 1 CPE/CSC 205: Software Engineering I Dr. Franz J. Kurfess Computer Science Department Cal Poly

© 2001 Franz Kurfess Object-oriented Design 40

Use-case DescriptionUse-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 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.

[Sommerville 01]

Page 36: © 2001 Franz Kurfess Object-oriented Design 1 CPE/CSC 205: Software Engineering I Dr. Franz J. Kurfess Computer Science Department Cal Poly

© 2001 Franz Kurfess Object-oriented Design 41

Architectural DesignArchitectural Design

once interactions between the system and its environment have been understood, this information is used for designing the system architecture

layered architecture is appropriate for the weather station interface layer for handling communications data collection layer for managing instruments instruments layer for collecting data

there should be no more than seven entities in an architectural model

[Sommerville 01]

Page 37: © 2001 Franz Kurfess Object-oriented Design 1 CPE/CSC 205: Software Engineering I Dr. Franz J. Kurfess Computer Science Department Cal Poly

© 2001 Franz Kurfess Object-oriented Design 42

Weather station architectureWeather station architecture

«subsystem»Data collection«subsystem»Instruments«subsystem»InterfaceWeather station Manages allexternalcommunicationsCollects andsummarisesweather dataPackage ofinstruments for rawdata collections

[Sommerville 01]

Page 38: © 2001 Franz Kurfess Object-oriented Design 1 CPE/CSC 205: Software Engineering I Dr. Franz J. Kurfess Computer Science Department Cal Poly

© 2001 Franz Kurfess Object-oriented Design 43

Object Identification

identifying objects (or object classes) is the most difficult part of object oriented design

there is no 'magic formula' for object identification it relies on the skill, experience and domain knowledge of

system designers

object identification is an iterative process it is unlikely to get it right the first time

[Sommerville 01]

Page 39: © 2001 Franz Kurfess Object-oriented Design 1 CPE/CSC 205: Software Engineering I Dr. Franz J. Kurfess Computer Science Department Cal Poly

© 2001 Franz Kurfess Object-oriented Design 44

Approaches to Object Identification

base the identification on tangible things in the application domain physical objects documents, data items known to the user

grammatical approach based on a natural language description of the system

(used in Hood method) behavioral approach identify objects based on what participates in what behavior

scenario-based analysis objects, attributes and methods in each scenario are

identified

[Sommerville 01]

Page 40: © 2001 Franz Kurfess Object-oriented Design 1 CPE/CSC 205: Software Engineering I Dr. Franz J. Kurfess Computer Science Department Cal Poly

© 2001 Franz Kurfess Object-oriented Design 45

Weather Station Object ClassesWeather Station Object Classes

ground thermometer, anemometer, barometer application domain objects ‘hardware’ objects related to the instruments in the system

weather station the basic interface of the weather station to its environment reflects the interactions identified in the use-case model

weather data encapsulates the summarized data from the instruments

[Sommerville 01]

Page 41: © 2001 Franz Kurfess Object-oriented Design 1 CPE/CSC 205: Software Engineering I Dr. Franz J. Kurfess Computer Science Department Cal Poly

© 2001 Franz Kurfess Object-oriented Design 46

Weather Station Object ClassesWeather Station Object ClassesidentifierreportWeather ()calibrate (instruments)test ()startup (instruments)shutdown (instruments)WeatherStationtest ()calibrate ()GroundthermometertemperatureAnemometerwindSpeedwindDirectiontest () Barometerpressureheighttest ()calibrate ()

WeatherDataairTemperaturesgroundTemperatureswindSpeedswindDirectionspressuresrainfallcollect ()summarise ()[Sommerville 01]

Page 42: © 2001 Franz Kurfess Object-oriented Design 1 CPE/CSC 205: Software Engineering I Dr. Franz J. Kurfess Computer Science Department Cal Poly

© 2001 Franz Kurfess Object-oriented Design 47

Further Objects and Object Refinement

use domain knowledge to identify more objects and operations weather stations should have a unique identifier weather stations are remotely situated so instrument

failures have to be reported automatically attributes and operations for self-checking are required

active or passive objects in this case, objects are passive and collect data on

request rather than autonomously introduces flexibility at the expense of controller processing

time

[Sommerville 01]

Page 43: © 2001 Franz Kurfess Object-oriented Design 1 CPE/CSC 205: Software Engineering I Dr. Franz J. Kurfess Computer Science Department Cal Poly

© 2001 Franz Kurfess Object-oriented Design 48

Design ModelsDesign Models

design models show the objects and object classes and relationships between these entities static models describe the static structure of the system

in terms of object classes and relationships dynamic models describe the dynamic interactions

between objects

[Sommerville 01]

Page 44: © 2001 Franz Kurfess Object-oriented Design 1 CPE/CSC 205: Software Engineering I Dr. Franz J. Kurfess Computer Science Department Cal Poly

© 2001 Franz Kurfess Object-oriented Design 49

Examples of Design Modelssub-system models

show logical groupings of objects into coherent subsystemssequence models

show the sequence of object interactionsstate machine models

show how individual objects change their state in response to events

other models use-case models, aggregation models, generalization

models, etc.

[Sommerville 01]

Page 45: © 2001 Franz Kurfess Object-oriented Design 1 CPE/CSC 205: Software Engineering I Dr. Franz J. Kurfess Computer Science Department Cal Poly

© 2001 Franz Kurfess Object-oriented Design 50

Subsystem ModelSubsystem Model

shows how the design is organized into logically related groups of objects

in UML, these are shown using packages packages are an encapsulation construct this is a logical model, the actual organization of objects in

the system may be different

[Sommerville 01]

Page 46: © 2001 Franz Kurfess Object-oriented Design 1 CPE/CSC 205: Software Engineering I Dr. Franz J. Kurfess Computer Science Department Cal Poly

© 2001 Franz Kurfess Object-oriented Design 51

Weather Station Subsystems«subsystem»InterfaceCommsControllerWeatherStation«subsystem»Data collection

«subsystem»InstrumentsAir thermometerWeatherData

Ground thermometer AnemometerWindVaneRainGaugeInstrumentStatusBarometer

[Sommerville 01]

Page 47: © 2001 Franz Kurfess Object-oriented Design 1 CPE/CSC 205: Software Engineering I Dr. Franz J. Kurfess Computer Science Department Cal Poly

© 2001 Franz Kurfess Object-oriented Design 52

Sequence ModelsSequence Models

sequence models show the sequence of object interactions that take place objects are arranged horizontally across the top time is represented vertically

models are read top to bottom

interactions are represented by labeled arrows different styles of arrow 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

[Sommerville 01]

Page 48: © 2001 Franz Kurfess Object-oriented Design 1 CPE/CSC 205: Software Engineering I Dr. Franz J. Kurfess Computer Science Department Cal Poly

© 2001 Franz Kurfess Object-oriented Design 53

Data collection sequence:CommsControllerrequest (report)acknowledge ()report ()summarise ()reply (report)acknowledge ()send (report):WeatherStation:WeatherData

[Sommerville 01]

Page 49: © 2001 Franz Kurfess Object-oriented Design 1 CPE/CSC 205: Software Engineering I Dr. Franz J. Kurfess Computer Science Department Cal Poly

© 2001 Franz Kurfess Object-oriented Design 54

State ChartsState Charts

show how objects respond to different service requests and the state transitions triggered by these 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 summarizing state

if calibrate() the system moves to a calibrating state a collecting state is entered when a clock signal is received

[Sommerville 01]

Page 50: © 2001 Franz Kurfess Object-oriented Design 1 CPE/CSC 205: Software Engineering I Dr. Franz J. Kurfess Computer Science Department Cal Poly

© 2001 Franz Kurfess Object-oriented Design 55

Weather Station State Diagram

Shutdown Waiting TestingTransmittingCollectingSummarisingCalibratingtransmission donecalibrate ()test ()startup ()shutdown () calibration OKtest completeweather summarycompleteclockcollectiondone

OperationreportWeather ()

[Sommerville 01]

Page 51: © 2001 Franz Kurfess Object-oriented Design 1 CPE/CSC 205: Software Engineering I Dr. Franz J. Kurfess Computer Science Department Cal Poly

© 2001 Franz Kurfess Object-oriented Design 56

Object Interface SpecificationObject Interface Specification

object interfaces have to be specified early objects and other components can be designed in parallel

designers should avoid designing the interface representation should be hidden in the object itself

objects may have several interfaces viewpoints on the methods provided

UML uses class diagrams for interface specification Java/JavaDocs may also be used

[Sommerville 01]

Page 52: © 2001 Franz Kurfess Object-oriented Design 1 CPE/CSC 205: Software Engineering I Dr. Franz J. Kurfess Computer Science Department Cal Poly

© 2001 Franz Kurfess Object-oriented Design 57

Weather Station Interface

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

[Sommerville 01]

Page 53: © 2001 Franz Kurfess Object-oriented Design 1 CPE/CSC 205: Software Engineering I Dr. Franz J. Kurfess Computer Science Department Cal Poly

© 2001 Franz Kurfess Object-oriented Design 58

Design Evolution

information hiding changes made to an object do not affect other objects in

an unpredictable way

assume pollution monitoring facilities are to be added to weather stations these sample the air and compute the amount of different

pollutants in the atmosphere pollution readings are transmitted with weather data

[Sommerville 01]

Page 54: © 2001 Franz Kurfess Object-oriented Design 1 CPE/CSC 205: Software Engineering I Dr. Franz J. Kurfess Computer Science Department Cal Poly

© 2001 Franz Kurfess Object-oriented Design 59

Example: Pollution Monitoring

add an object class called AirQuality as part of WeatherStation

add an operation reportAirQuality to WeatherStation modify the control software to collect pollution readings

add objects representing pollution monitoring instruments

[Sommerville 01]

Page 55: © 2001 Franz Kurfess Object-oriented Design 1 CPE/CSC 205: Software Engineering I Dr. Franz J. Kurfess Computer Science Department Cal Poly

© 2001 Franz Kurfess Object-oriented Design 60

Example: Pollution MonitoringNODatasmokeDatabenzeneDatacollect ()summarise ()Air qualityidentifierreportWeather ()reportAirQuality ()calibrate (instruments)test ()startup (instruments)shutdown (instruments)WeatherStationPollution monitoring instrumentsNOmeterSmokeMeterBenzeneMeter

[Sommerville 01]

Page 56: © 2001 Franz Kurfess Object-oriented Design 1 CPE/CSC 205: Software Engineering I Dr. Franz J. Kurfess Computer Science Department Cal Poly

© 2001 Franz Kurfess Object-oriented Design 63

Important Concepts and TermsImportant Concepts and Terms object object class object identification object-oriented analysis (OOA) object-oriented design (OOD) object-oriented programming

(OOP) operation package passive object reusability server state subsystem system architecture Unified Modeling Language

(UML)

active object association attribute class concurrent context design evolution design model encapsulation generalization hierarchy information hiding inheritance interface message passing

Page 57: © 2001 Franz Kurfess Object-oriented Design 1 CPE/CSC 205: Software Engineering I Dr. Franz J. Kurfess Computer Science Department Cal Poly

© 2001 Franz Kurfess Object-oriented Design 64

OOD is a popular approach to design design components have 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

UML provides different notations for defining different object models

Summary

[Sommerville 01]

Page 58: © 2001 Franz Kurfess Object-oriented Design 1 CPE/CSC 205: Software Engineering I Dr. Franz J. Kurfess Computer Science Department Cal Poly

© 2001 Franz Kurfess Object-oriented Design 65

Summary (cont.)

a range of different models may be produced during an object-oriented design process these include static and dynamic system models

object interfaces should be defined precisely e.g. using a programming language like Java

object-oriented design simplifies system evolution

[Sommerville 01]

Page 59: © 2001 Franz Kurfess Object-oriented Design 1 CPE/CSC 205: Software Engineering I Dr. Franz J. Kurfess Computer Science Department Cal Poly

© 2001 Franz Kurfess Object-oriented Design 66