Post on 19-Dec-2015
transcript
Object-Oriented Object-Oriented Software EngineeringSoftware Engineering
More Modelling with ClassesMore Modelling with Classes
Paul J KrausePaul J Krause
More Modelling with ClassesMore Modelling with Classes
ContentsContents Overview of Associations Overview of Associations Generalisation/Specialisation hierarchiesGeneralisation/Specialisation hierarchies AggregationAggregation Why I don’t like aggregationWhy I don’t like aggregation InterfacesInterfacesSome examples taken from: Mellor and Some examples taken from: Mellor and
Balcer, Balcer, Executable UMLExecutable UML, Addison Wesley, Addison Wesley
AggregationAggregationSurf List
surfListSize
addSurfChanneldeleteSurfChannelsetSurfChannel
Source ID
presetNumberpresetName
setPresetNumbersetPresetName
0..*
Putting it all togetherPutting it all together
A/V Source
Front End External Source
Surf List
Source ID
0..*
11
Tuner
1..*
is tuned to
Publisher
nameaddresswebSite
BookProduct
bookNumbertitleunitPrice
Customer
nameemailshippingAdd
Author
nameaddresswebSite
R1 R3
R2
is producedand
marketedby
producesand
markets
is apurchase
of
is sold as
wrote
was written by
1 0..* 1..* 0..*
1..*
1..*
Order
quantitysalePricedate
makes 1..*
is made by 1
““Nonuniform Classes”Nonuniform Classes”
Consider an on-line “book store”. It may Consider an on-line “book store”. It may actually sell a variety of products.actually sell a variety of products.
Product
productID: ProductCodetitle: stringcopyright: YearunitPrice: Moneydescription: stringbookNumber: ISBNsubtitle: stringrecordingLength: TimeproductVersion: string
applicable to allProducts
only forBooks
only for Recordings (CDs, videos …)
only for Software
Separate Product Classes?Separate Product Classes?
BookProduct
productID: title: copyright:unitPrice:description:bookNumber:subtitle:
RecordingProduct
productID: title: copyright:unitPrice:description:recordingLength:
SoftwareProduct
productID: title: copyright:unitPrice:description:productVersion:
Partitioning ProductsPartitioning Products
All Products
Recording Products
Book ProductsBook Products
No Products remain outside a set No products are in more than one set
Generalisation - SpecialisationGeneralisation - Specialisation
BookProduct
bookNumber:subtitle:
RecordingProduct
recordingLength:
SoftwareProduct
productVersion:
Product
productID: title: copyright:unitPrice:description:
R11 {disjoint, complete}
DefinitionsDefinitions
A A superclasssuperclass is a class that is a generalisation of is a class that is a generalisation of a set of conceptsa set of concepts
A A subclasssubclass is a specialisation of a high-level is a specialisation of a high-level conceptconcept
A A leaf-subclassleaf-subclass is a subclass that is not also a is a subclass that is not also a superclass of another classsuperclass of another class
Generally, superclasses will be Generally, superclasses will be abstract classesabstract classes it is not normally possible to create instances of themit is not normally possible to create instances of them
Repeated SpecialisationRepeated SpecialisationAccount
{abstract}
CheckingAccount{abstract}
SavingsAccount
RegularCheckingAccount InterestCheckingAccount
R1 {disjoint, complete}
R2 {disjoint, complete}
Adding an AssociationAdding an Association
Publisher
groupCode:publisherCode:name:address:website:
isproducedandmarketedby
producesand
markets
1 0..*R1
BookProduct
bookNumber:subtitle:
RecordingProduct
recordingLength:
SoftwareProduct
productVersion:
Product
productID: title: copyright:unitPrice:description:
R11 {disjoint, complete}
Aggregation - “part of”Aggregation - “part of”
Vehicle
TransmissionEngine Wheels
“A Vehicle is an aggregation (made up) of an Engine, a Transmission and some Wheels (and some more stuff… )”
Complex structures?Complex structures?
PictureSoundFeaturesInstallationFeatures Timer
Parental ControlChild LockSleep
Parental Control Block AllClearTV RatingFilm RatingTV Rating TV Y
TV Y7PGTV 14 …
CarAeroplane TruckBicycle
SportsCar
Vehicle
VehicleComponent
1..*1..*
EngineTransmissionWheel
JetEngine PistonEngine ElectricMotor
Amphibious Vehicle
Aeroplanes, Bicycles, Cars, Trucks and Amphibious Vehicles are "kinds of" Vehicle
A Sports Car is a "kind of" Car
A Vehicle is an "aggregation" of VehicleComponents
Wheel, Transmission and Engine are "kinds of" VehicleComponents
JetEngine, PistonEngine and ElectricMotor are "kinds of" Engine
NOTE: In this model I may want to add in some additional constraints on what kinds of VehicleComponents are associated with specific kinds of Vehicle
Avoiding AggregationAvoiding Aggregation
Vehicle
Engine
powers
ispoweredby
1
1..*
Transmission
Wheel
transmitspower
through
isdriven by
11 0,1
1..* generatesmotionvia
isrotatedby
issupportedby1..*
1
supports
Aggregation - Who needs it?Aggregation - Who needs it?
Menu
MenuItem
1..*
LeafItem SubMenu
1
isselected from
selects
1
1
consists of
is contained in
InterfacesInterfaces
Sometimes we may find two or more Sometimes we may find two or more different subclasses share some common different subclasses share some common behaviourbehaviour
In this case, they are not strictly “kinds of” In this case, they are not strictly “kinds of” some common parentsome common parent
Rather, they “behave like” some common Rather, they “behave like” some common pattern (under certain circumstances)pattern (under certain circumstances)
We say that they both implement a We say that they both implement a common interfacecommon interface