Article Preview
Buy Now
COLUMN
Is an Employee a Person?
Subclassing an employee class
Issue: 1.5 (April/May 2003)
Author: Charles Yeomans
Author Bio: Charles Yeomans is a software developer in Lexington, Kentucky.
Article Description: No description available.
Article Length (in bytes): 5,012
Starting Page Number: 36
Article Number: 1518
Related Link(s): None
Excerpt of article text...
You're writing a small business accounting application, so of course you'll want to add an employee class. And, since the majority of businesses only employ people, class Employee should inherit from class Person. But what happens when this person leaves the employ of the company using your software, and returns as a consultant?
I've encountered this very problem in some well-known Macintosh accounting applications. What happens is that your user will be forced to re-enter the person's information to reincarnate him as a consultant.
One alternative to subclassing would be to define Employee and Vendor interfaces, and have Person implement both interfaces. But this doesn't feel right; the result is to turn the Person class into a union of the Employee and Vendor. If we consider this solution from the database end, it's clear that there will be a lot of wasted space as fields go unused for the majority of people who are not vendors.
...End of Excerpt. Please purchase the magazine to read the full article.