- Uses of Object Inheritance
- The Most Useful Aspects of Object Inheritance
- Implementing Object Inheritance
- Conclusion
The Most Useful Aspects of Object Inheritance
Because we know that most languages do not directly support object inheritance, we limit ourselves to those ideas that are the most useful. It turns out that there are two concepts related to object inheritance that are really useful. First, a child object should be able to act as a partial stand-in for its parent. Second, a child object should be able to answer messages in the same way and with the same values as its parent.
Although the second concept seems more obviously useful, the motivation behind making the child object a stand-in for its parent is a little more obscure. The objects that are related through object inheritance represent a single real-world entity. The actor and its roles represent a single person; the specific item and its item description represent a single thing; the composite transaction and its line items represent a single real-world event. When the other objects in the system are working with one of the child objects, what they are really doing is working with the combined entity in a particular context. Therefore, the other objects will expect the children to be able to provide many of the same capabilities as their parents.
In addition to useful features, there are useful restrictions when applying object inheritance to a business model. Because a child object represents its parent only in a specific context, it does not make sense for the child to be able to change its parent. Any changes made could be invalid in other contexts. Additionally, the parent's collaborations with other objects should be visible to its children only if they make sense for all of the children of a given type. For example, a line item in a sales transaction would not inherit the relationship between the sale and a subsequent shipment transaction because it is possible that not all line items are included in a given shipment.