Send messages to components instead of to self

From CSSEMediaWiki
(Difference between revisions)
Jump to: navigation, search
(Favor over inheritance)
Line 1: Line 1:
 
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.
 
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.
  
 
[[Category: Johnson and Foote's heuristics]]
 
[[Category: Johnson and Foote's heuristics]]

Revision as of 05:01, 14 October 2009

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