chapter 14: object-oriented design
Post on 12-Jan-2016
43 Views
Preview:
DESCRIPTION
TRANSCRIPT
Slide 1
Chapter 14: Object-Oriented Design
Object-oriented design
based on abstractions of real-world or system entities
objects manage a private state
communication by message passing
advantages
• obvious map to real-world
• easier to debug due to reduced system coupling
• easier reuse
• easier maintenance (objects are stand-alone entities)
Functional design
based on interacting functional components of a solution
functions share a global state
communication via shared variables
advantages
• functional data flow may be more intuitive
• more obvious control model
Slide 2
Object-oriented developmentThree related but distinct OO stages
• analysis (OOA) : develop an object model of the application domain
• design (OOD): develop an object-oriented system model to implement requirements
• programming (OOP) : realize an OOD using an OO language such as C++
Commonalities:• identifying objects, attributes and services
• organizing objects into an aggregation hierarchy
• constructing object-use descriptions to show how services are used
• specifying object interfaces
Slide 3
Passive and active objectsPassive objects
• all state changes effected through operations defined in the object interface
• e.g. aStack.Push(item)
Active objects• can change their own state
• e.g. an object might have a (private) timer to update its state every 100 ms (similar to JavaScript setTimeout)
Slide 4
14.2 Object identificationThe most difficult part of object oriented design
No 'magic formula' for object identification
Relies on skill, experience, and domain knowledge
Iterative--you are unlikely to get it right first time
How is this like anything else you do well?
Approaches• grammatical based on a description of the system: nouns are objects,
adjectives are attributes, verbs are operations• identify tangible things in the application domain• behavioral, identifying objects based on what participates in what behavior• scenario analysis
Slide 5
An office information system
The Office Information Retrieval System (OIRS) is an automatic file clerk which can file documents under some name in one or more indexes, retrieve documents, display and maintain document indexes, archive documents and destroy documents. The system is activated by a request from the user and always returns a message to the user indicating the success or failure of the request.
Slide 6
An office information systemThe Office Information Retrieval System (OIRS) is an automatic file clerk which can file documents under some name in one or more indexes, retrieve documents, display and maintain document indexes, archive documents and destroy documents. The system is activated by a request from the user and always returns a message to the user indicating the success or failure of the request.
FileRetrieveArchiveDestroy
Document
NameNameDisplayDelete entryAdd entry
Index
Put message
User Retrievalsystem
Name Name User commandGet command
Slide 7
Weather mapping system A weather mapping 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 system 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 digitised 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.
Will look at this two ways 1. non-layered 2. layered
Slide 8
Top-level architecturesNon-layered Layered
«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 and
integrating 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
Weatherdata processor
Dataarchive
Mapdatabase
Telecommssystem
Satellitereceiver
Mapprinter
Mapdisplay
Manual datacollection
Weatherstations
Slide 9
Subsystems derived from layered view
Datastorage
Userinterface
«subsystem»Data collection
«subsystem»Data processing
«subsystem»Data archiving
«subsystem»Data display
Weatherstation
Satellite
Comms
Balloon
Observer
Map store Data store
Datastorage
Map
Userinterface
Mapdisplay
Mapprinter
Datachecking
Dataintegration
Slide 10
Comment on notationThe design is organized into logically related groups of objects
In the UML, these are encapsulated using packages
This is a logical model
The actual organization of objects in the system may be different
Next step: decompose weather station subsystem
Slide 11
Weather station objects 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, therefore 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• this introduces flexibility at the expense
of controller processing time
What are the objects inside this?
IdentifierWeather dataInstrument status
InitializeTransmit dataTransmit statusSelf testShut down
Weather station
Slide 12
Hardware control objects
Test
Wind vane
Direction
ResetTest
Rain gauge
Rainf all
TestCalibr ate
Barometer
PressureHeight
TestCalibr ate
Airthermometer
Temperature
TestCalibr ate
Groundthermometer
Temperature
Test
Anemometer
Wind speed
Slide 13
Weather data objects
Air temperature dataGround temperature data
Wind speed dataWind direction dataPressureRainf all
Mak e readingsProcess data
Weather data
Readings
MaximumMinimumAver ageRead
Temperature data
Readings
ReadAver age
Pressure
Readings
Aver ageMax. gust
Read
Wind speed data
Readings
Read
Wind directiondata
Cumulativ e
Read
Rainfall
Slide 14
Weather station subsystems (layered)
«subsystem»Interface
«subsystem»Data collection
CommsController
WeatherStation
WeatherData
InstrumentStatus
«subsystem»Instruments
Air thermometer
Ground thermometer
RainGauge
Barometer
Anemometer
WindVane
Slide 15
Object interface designSpecify the detail of the object
interfaces so that objects can be developed in parallel
This means defining• attribute types
• the signatures and semantics of object operations
Use a programming language to achieve precision
Avoid representation information
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
Slide 16
Design evolutionHow would you add pollution monitoring facilities to the weather stations?
(to sample the air and compute the amounts of different pollutants)
(pollution readings are transmitted with weather data)
Changes required:• 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.
identifier
reportWeather ()reportAirQuality ()
calibrate (instruments)test ()startup (instruments)
shutdown (instruments)
WeatherStation
NODatasmokeDatabenzeneData
collect ()summarise ()
Air quality Pollution monitoring instruments
NOmeter SmokeMeter
BenzeneMeter
Slide 17
Weather station subsystems (layered)
«subsystem»Interface
«subsystem»Data collection
CommsController
WeatherStation
WeatherData
InstrumentStatus
«subsystem»Instruments
Air thermometer
Ground thermometer
RainGauge
Barometer
Anemometer
WindVane
NO meter Smoke meter Benzine meter
Slide 18
Other pieces mentioned in text
State machines show responses
to requests for services
Sequence diagrams show
interactions among objects
:CommsController
request (report)
acknowledge ()report ()
summarise ()
reply (report)
acknowledge ()
send (report)
:WeatherStation :WeatherData
transmission done
calibrate ()
test ()startup ()
shutdown ()
calibration OK
test complete
weather summarycomplete
clock collectiondone
Operation
reportWeather ()
Shutdown Waiting Testing
Transmitting
Collecting
Summarising
Calibrating
top related