CSC/ECE 517 Fall 2010/ch3 S30 RJ
Decomposition, Message Forwarding, and Delegation versus Inheritance in OOP Design
Most OOP overviews explain what the concept of Inheritance is in Object Oriented Programming, and how Inheritance works, but not many OOP overviews discuss alternatives when Inheritance may not be the best design choice for an OO application. This topic briefly introduces the OOP concepts of Inheritance, Decomposition, Message Forwarding, and Delegation, and then discusses when Decomposition, Message Forwarding, and Delegation could be considered as potential alternatives to the use of Inheritance for some OOP applications.
Inheritance in OOP Design
Inheritance is one of the key concepts in Object Oriented Programming. In the realm of human families, the concept of inheritance is used to explain how children receive or acquire similar biological and physiological traits directly from their parents. In addition, in the realm of family financial planning, the term inheritance is used to describe the process whereby family heirs receive financial benefits and resources from the estates of older family members, typically involving parents and children relationships. In OOP, parent classes describe and define attributes and capabilities of objects in a parent class. Subsequently subclasses can be defined to create objects that inherit or acquire the attributes and capabilities of objects that belong to the parent class, or Superclass of the child, or subclass. Programming code that is created by programmers to describe the attributes and methods of objects in a parent class can easily be reused by objects that are created in subclasses of the parent class.
Decomposition in OOP Design
A useful starting definition for Decomposition in OOP is "In OO decomp, we think in terms of identifying active, autonomous agents which are responsible for doing the work, and which communicate with each other to get the overall problem solved." [1]
The 'autonomous agents' mentioned above would correspond to leveraging known classes and their various objects to get a task or process done, rather than taking the time to design a grand Superclass and subclass inheritance hierarchy which contains all the needed objects and classes that are required to address a given task or process. Mixins in Ruby on Rails would be an example of decomposition in OOP, since Mixins allow useful methods from classes to be easily mixed-in, or used as utility methods by classes that may not be suitably related in a traditional inheritance hierarchy.
Message Forwarding in OOP Design
Delegation in OOP Design
References:
References: <references/>