Presentation is loading. Please wait.

Presentation is loading. Please wait.

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”

Similar presentations


Presentation on theme: "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”"— Presentation transcript:

1

2

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.


Download ppt "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”"

Similar presentations


Ads by Google