Presentation is loading. Please wait.

Presentation is loading. Please wait.

a generalization is a relationship between a general thing (the

Similar presentations


Presentation on theme: "a generalization is a relationship between a general thing (the"— Presentation transcript:

1 a generalization is a relationship between a general thing (the
Generalization (Ch 26) 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 MemberOfStaff is a specialized kind of LibraryMember LibraryMember MemberOfStaff Nov 2002 R McFadyen

2 everything a LibraryMember can do, a MemberOfStaff can do
Generalization example continued: everything a LibraryMember can do, a MemberOfStaff can do a LibraryMember can borrow a book, so can a MemberOfStaff there are some things that a MemberOfStaff can do that a LibraryMember cannot (the specialization aspect) the MemberOfStaff has all the attributes the LibraryMember has, and possibly more (again, the specialization aspect) MemberOfStaff Nov 2002 R McFadyen

3 A generalization hierarchy
a Generalization example: a SavingsAccount is a specialized kind of BankAccount a ChequingAccount is a specialized kind of BankAccount an Asset may be a BankAccount, RealEstate, or a Security Asset RealEstate BankAccount Security SavingsAccount ChequingAccount A generalization hierarchy Nov 2002 R McFadyen

4 The subclass must conform to 100% of the superclass’s: attributes
Text: 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 A conceptual subclass is a kind of superclass - is-a-kind-of is usually referred to as is-a A ROT/recommendation Nov 2002 R McFadyen

5 Generalization/specialization
Student A constraint can be added to be very specific about an association Complete vs incomplete Overlapping vs disjoint. {complete} PartTime FullTime Person Student {overlapping} Employee Supervisor {disjoint} PartTime FullTime Nov 2002 R McFadyen

6 Figure 26.7 Every payment, regardless of whether it is cash, credit, or cheque, has an Amount and it is associated with a Sale Pays-for Payment Sale 1 1 Amount: money Cash Payment Credit Payment Cheque Payment * 1 Only credit payments are associated with credit cards Only cheque payments are associated with cheques 1 1 CreditCard Cheque Nov 2002 R McFadyen

7 Motivation for partitioning a conceptual class into subclasses:
the subclass has additional attributes of interest the subclass has additional associations of interest the 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 full time employee will have different associations from a part time employee Nov 2002 R McFadyen

8 Figure 26.7 If every member of a class must be a member of a subclass, then the superclass is considered an abstract class - it is never instantiated. Abstract classes have their name italicized. Pays-for Payment Sale 1 1 Amount: money Cash Payment Credit Payment Cheque Payment * 1 1 1 CreditCard Cheque Nov 2002 R McFadyen

9 ROT: Do not model with subclasses. Model with states.
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: Its difficult to mutate an object from one class to another Payment Unauthorized Payment Authorized Payment Nov 2002 R McFadyen

10 Text: Instead of Payment Unauthorized Payment Authorized Payment Use:
Is-in Payment PaymentState 1 1 Unauthorized State Authorized State Nov 2002 R McFadyen


Download ppt "a generalization is a relationship between a general thing (the"

Similar presentations


Ads by Google