Download presentation
Presentation is loading. Please wait.
Published byGodwin Phelps Modified over 9 years ago
3
Class Relationships A class defines a type of data Composition allows an object of another class to define an attribute of a class –Employee “has a” Date Inheritance allows more specific versions (subclasses) of a class to be defined –SalariedEmployee “is a” Employee –A subclass can “extend” only one class (single inheritance)
4
Employee-Payroll Example Look at pages 457-466 in textbook One superclass: –Employee Three subclasses of Employee: –SalariedEmployee –CommissionEmployee –HourlyEmployee One subclass of CommissionEmployee: –BasePlusCommissionEmployee
5
How could we add Composition? Date? Currency? What else?
6
How do we know when we need a subclass??? Superclass: –General case –What ALL employees have (attributes) or do (methods) Subclass: –More specific case –What particular types of employees have (attributes) or do (methods)
7
What about polymorphism??? Superclass: – defines what ALL employees do – earn money! Subclass: – define specific ways this is calculated –SalariedEmployees get fixed earnings –HourlyEmployees get paid by the hour –CommissionEmployees’ earnings include a commission BasePlusCommissionEmployees are a more specific type of CommissionEmployee – they earn a base salary plus commission
8
Class Diagram Create a class diagram to show the class relationships of the Employee-Payroll class hierarchy. Include two additional composition classes.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.