Send messages to components instead of to self

From CSSEMediaWiki
Jump to: navigation, search

For an inheritance-based framework, behaviours that can be achieved by overriding methods are better achieved by encapsulating these methods into components. It can help the framework to be able to work with pluggable objects, and it helps to increase the cohesion and generality of such a framework. Johnson and Foote 1988 suggest that this kind of refactoring should be done whenever possible. As an example, they give sorting methods which often take parameters describing how to compare objects, as opposed to subclasses for each kind of comparison that could be performed.

This is similar to Favor composition over inheritance maxim.

Personal tools