Why is this impossible? This is the exact reason to use object oriented programming. The person class should have a PersonID which is a unique value. Why can't a worker class and a student class point to the same person? I think their problem was how they were perceiving the data. Obviously, the worker can't be of the same type as the student. When you grab data (from a database in my example) you would most likely would be grabbing a specific type. You would either have tables that holds workers and students or you would have a Person sub table that would be able to hold additional or multiple types. Below is an image of the second description in how it would look.
Again, I believe they were having trouble imagining this in their head. Yes, you can't have two objects that are of different types as one type. You're not ever supposed to. A Ferrari is not an F-150. They can't be and aren't supposed to be. A worker is not a student. A student is not a worker. A person who works CAN be a person who is a student and a person who is a student CAN be a person who is a worker. I don't give grades to workers and I don't think any college would plan on paying any student a salary.
No comments:
Post a Comment