Design Question: Should I build up my objects through inheritance?

Design Question: Should I build up my objects through inheritance?

Old forum URL: forums.lhotka.net/forums/t/3074.aspx


DeHaynes posted on Friday, June 22, 2007

I am building a system to keep track of Employees.  In the system, for each employee, I also keep track of family members AND Next of Kin.  As I was coding the employee object, it struct me that I am going to need about 90% of the same code for a relative (family member) object and a Next of Kin object.  So my question is:

   Should I build a generic Contact Object with all the basic data for a person.   Then inherit from that to build a employee object, relative object and Next of Kin object?

Thanks in advance.

malloc1024 replied on Friday, June 22, 2007

Inheritance should be based on behavior not data.  Properties are data not behavior.  If your object shares behavior, inheritance can be considered.  However, keep in mind that you should favor composition over inheritance.

DeHaynes replied on Friday, June 22, 2007

Thanks for the response.

I had soon come to a similiar conclusion after writing that but I left it just in case someone had a different experience.

Copyright (c) Marimer LLC