I'm implementing a basic payroll program in Java. I have an abstract super class called Employee
that mainly stores data like tax ID, name, etc. I then have 2 subclasses of Employee
called Hourly
and Salaried
which are supposed to represent types of employee. Those two classes implement calculations of pay and tax, and store data specific to their employee types.
The trouble is, I'm ending up with heaps of fields as new fields need to be implemented to store the calculated pay, tax, etc. Would I be justified in getting rid of Salaried
and Hourly
and creating a new super class, PayCalculation
, then having PayHourly
and PaySalaried
classes stemming off this to implement the hourly/salaried specific fields and calculations? If so, would it make sense to have a composition relationship between Employee
(super class) and PayCalculation
(subclass)?
I don't have a great understanding of composition. If anyone could think of a better way to structure this I would much appreciate it.
I don't know how to use UML, but here's a pretty shoddy diagram I made in paint to explain this.