All atomic-powered posts from June 2006:
Composition vs. Inheritance
A little while ago, someone posted to our website a question of design. I was in the middle of crafting a response when I decided that I probably couldn’t speak for the whole of Atomic Object, and since this response would represent Atomic, I asked for input from all corners. I think the answers are pretty interesting. So I posted the question, followed by a long series of responses… Original question from Mike:
“I was wondering if I may ask your opinion on a design issue. I read your tutorial pages on Composition (Aggregation) vs. Inheritance and found them very instructive toward my OO design.
Application: Let’s say you have an “Asset” class whose objects will be part of a collection. The purpose is to keep track of the hardware assets(computers) assigned to an employee. An Asset has an ID#, Manufacturer, Warranty Expiration Date etc. It also has a Type. Type could be a PC, laptop, or server (Whichever is assigned to a given employee).
Read the rest of this entry