3 ms·
How would you design something like : Person --> Full Time Employee --> Manager Person --> Contract Employee Without inheritance assuming that salary calcula
by thewarrior 12y ago
How would you design something like :
Person --> Full Time Employee --> Manager
Person --> Contract Employee
Without inheritance assuming that salary calculation is the only thing which differentiates them.
- derefr 12y agoSomething like... Person HAS A IEmploymentRelationship ContractEmployment IMPLEMENTS IEmploymentRelationship FullTimeEmployment IMPLEMENTS IEmploymentRelationship FullTimeEmployment HAS A IDirectReport Manager HAS A Person Manager IMPLEMENTS IDirectReport And then salary() is a polymorphic function declared by the IEmploymentRelationship interface, where FullTimeEmployment instances use the manager somehow, and ContractEmployment doesn't. You can even put some sugar on that by having a salary() function on Person that calls the salary() function on its IEmploymentRelationship—but I wouldn't, for the same reason I wouldn't denormalize a relational database.
- thewarrior 12y agoGot it. Thank you.