Download presentation
Presentation is loading. Please wait.
1
Object-Oriented Software Engineering More Modelling with Classes Paul J Krause
2
More Modelling with Classes Contents Overview of Associations Generalisation/Specialisation hierarchies Aggregation Why I don’t like aggregation Interfaces Some examples taken from: Mellor and Balcer, Executable UML, Addison Wesley
3
Class Tuner class name channel frequency attributes get_Frequency set_Frequency operations
4
Inheritance Hierarchy Tuner A/V TunerFM Tuner
5
Aggregation Surf List surfListSize addSurfChannel deleteSurfChannel setSurfChannel Source ID presetNumber presetName setPresetNumber setPresetName 0..*
6
Association Tuner Surf List 1 1
7
Putting it all together A/V Source Front EndExternal Source Surf List Source ID 0..* 1 1 Tuner 1..* is tuned to
8
Publisher name address webSite BookProduct bookNumber title unitPrice Customer name email shippingAdd Author name address webSite R1R3 R2 is produced and marketed by produces and markets is a purchase of is sold as wrote was written by 10..*1..* 0..* 1..* Order quantity salePrice date makes1..* is made by 1
9
“Nonuniform Classes” Consider an on-line “book store”. It may actually sell a variety of products. Product productID: ProductCode title: string copyright: Year unitPrice: Money description: string bookNumber: ISBN subtitle: string recordingLength: Time productVersion: string applicable to all Products only for Books only for Recordings (CDs, videos …) only for Software
10
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:
11
Partitioning Products All Products Recording Products Book Products No Products remain outside a set No products are in more than one set
12
Generalisation - Specialisation BookProduct bookNumber: subtitle: RecordingProduct recordingLength: SoftwareProduct productVersion: Product productID: title: copyright: unitPrice: description: R11 {disjoint, complete}
13
Definitions A superclass is a class that is a generalisation of a set of concepts A subclass is a specialisation of a high-level concept A leaf-subclass is a subclass that is not also a superclass of another class Generally, superclasses will be abstract classes it is not normally possible to create instances of them it is not normally possible to create instances of them
14
Repeated Specialisation Account {abstract} CheckingAccount {abstract} SavingsAccount RegularCheckingAccountInterestCheckingAccount R1 {disjoint, complete} R2 {disjoint, complete}
15
Adding an Association Publisher groupCode: publisherCode: name: address: website: is produced and marketed by produces and markets 1 0..* R1 BookProduct bookNumber: subtitle: RecordingProduct recordingLength: SoftwareProduct productVersion: Product productID: title: copyright: unitPrice: description: R11 {disjoint, complete}
16
Aggregation - “part of” Vehicle TransmissionEngineWheels “A Vehicle is an aggregation (made up) of an Engine, a Transmission and some Wheels (and some more stuff… )”
17
Complex structures? Picture Sound Features Installation Features Timer Parental Control Child Lock Sleep Parental Control Block All Clear TV Rating Film Rating TV Rating TV Y TV Y7 PG TV 14 …
18
Menu MenuItem 1..* LeafItemSubMenu 1 is selected from selects 1
20
Avoiding Aggregation Vehicle Engine powers is powered by 1 1..* Transmission Wheel transmits power through is driven by 1 10,1 1..* generates motion via is rotated by is supported by 1..* 1 supports
21
Aggregation - Who needs it? Menu MenuItem 1..* LeafItemSubMenu 1 is selected from selects 1 1 consists of is contained in
22
Interfaces Sometimes we may find two or more different subclasses share some common behaviour In this case, they are not strictly “kinds of” some common parent Rather, they “behave like” some common pattern (under certain circumstances) We say that they both implement a common interface
23
A “Cashier” Interface PersonMachine ATMEmployee «interface» Cashier withdraw deposit
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.