Download presentation
Presentation is loading. Please wait.
Published byAmbrose Hines Modified over 9 years ago
1
2007ACS-3913 Ron McFadyen1 Generalization a generalization is a relationship between a general thing (the superclass or parent class) and a more specific kind of thing (the subclass or child class) example: a StaffMember is a specialized kind of LibraryMember a StudentMember is a specialized kind of LibraryMember LibraryMember StaffMemberStudentMember
2
2007ACS-3913 Ron McFadyen2 Generalization Multiple subclasses can be grouped to indicate they are related subclasses LibraryMember StaffMemberStudentMember It then becomes meaningful to consider certain constraints: complete, incomplete, disjoint, overlapping
3
2007ACS-3913 Ron McFadyen3 Generalization Inheritance of attributes and behaviour: everything a LibraryMember can do, a StaffMember can do everything a LibraryMember can do, a StudentMember can do If a LibraryMember can borrow a book, so can a StaffMember and a StudentMember a StaffMember and a StaffMember have all the attributes the LibraryMember has, and possibly more Specialization: there are some things that a specialized class can do that a LibraryMember cannot LibraryMember StaffMemberStudentMember
4
2007ACS-3913 Ron McFadyen4 example: a SavingsAccount is a specialized kind of BankAccount a ChequingAccount is a specialized kind of BankAccount a BankAccount is a specialized kind of Asset RealEstate is … Asset RealEstateBankAccountSecurity SavingsAccountChequingAccount
5
2007ACS-3913 Ron McFadyen5 All members of a conceptual subclass set are members of their superclass set 100% of the conceptual superclass’s definition should be applicable to the subclass. The subclass must conform to 100% of the superclass’s: attributes associations
6
2007ACS-3913 Ron McFadyen6 Payment Amount: money Cash Payment Credit PaymentCheque Payment Sale Pays-for 1 1 Every payment, regardless of whether it is cash, credit, or cheque, has an Amount and it is associated with a Sale CreditCardCheque 1 1 1 *
7
2007ACS-3913 Ron McFadyen7 Motivation for partitioning a class into subclasses: subclass has additional attributes of interest subclass has additional associations of interest subclass is operated on, handled, reacted to, or manipulated differently than the superclass or other subclasses the subclass concept represents an animate thing that behaves differently than the superclass or other subclasses Examples a chequing account will accrue interest differently from a savings account a loan account will have different associations from a savings account
8
2007ACS-3913 Ron McFadyen8 Watch for objects that are performing roles, or moving from one state to another. ROT: Do not model with subclasses. Model with states. Text: Consider payments that begin as unauthorized and may eventually become authorized. Do not model as: Payment Unauthorized Payment Authorized Payment
9
2007ACS-3913 Ron McFadyen9 Instead of Payment Unauthorized Payment Authorized Payment Use: PaymentState Unauthorized StateAuthorized State Payment Is-in * 1 See the State pattern
10
2007ACS-3913 Ron McFadyen10 PaymentState Unauthorized StateAuthorized State Payment Is-in * 1 authorize() cancel() getStatus() cancel() A payment that is not authorized has an authorize operation, but authorize cannot be executed by a payment that has already been authorized. Cancel has two different implementations (polymorphism). Every payment has getStatus and cancel operations
11
2007ACS-3913 Ron McFadyen11 dogcat Constraints Shown inside curly braces {…} incomplete complete disjoint overlapping mammal {disjoint, incomplete}
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.