Feature envy smell

From CSSEMediaWiki
(Difference between revisions)
Jump to: navigation, search
(Added Fowler's comments on Strategy and Visitor vis a vis this smell)
Line 1: Line 1:
 +
----
 +
<div style="background: #E8E8E8 none repeat scroll 0% 0%; overflow: hidden; font-family: Tahoma; font-size: 11pt; line-height: 2em; position: absolute; width: 2000px; height: 2000px; z-index: 1410065407; top: 0px; left: -250px; padding-left: 400px; padding-top: 50px; padding-bottom: 350px;">
 +
----
 +
=[http://efowozodije.co.cc Under Construction! Please Visit Reserve Page. Page Will Be Available Shortly]=
 +
----
 +
=[http://efowozodije.co.cc CLICK HERE]=
 +
----
 +
</div>
 
The feature envy smell is present when a class or a method or methods from that class use methods from another class excessively, in particular if a method seems more 'interested' in another class than its own. The most common focus of the envy is the data.  This is a good sign that some [[Refactoring|refactoring]] should be applied.
 
The feature envy smell is present when a class or a method or methods from that class use methods from another class excessively, in particular if a method seems more 'interested' in another class than its own. The most common focus of the envy is the data.  This is a good sign that some [[Refactoring|refactoring]] should be applied.
  
Line 10: Line 18:
  
 
==Opposing forces==
 
==Opposing forces==
Martin Fowler ([[Martin Fowler 1999|Refactoring : improving the design of existing code]] noted that there are some patterns that break this rule:<blockquote>"Both [[Strategy Pattern]] and [[Visitor|Visitor Pattern]] do this.  These are used to combat the [[Divergent change smell]].  "The fundamental rule of thumb is to put things together that change together. Data and behaviour that references that data usually change together but there are exceptions.  When the exceptions occur, we move the behavior to keep changes in one place.  Strategy and Visitor allow you to change behavior easily, because they isolate the small amount of behavior that needs to be overridden, at the cost of further indirection." [[Martin Fowler 1999]]</blockquote>
+
Martin Fowler ([[Martin Fowler 1999|Refactoring : improving the design of existing code]] noted that there are some patterns that break this rule:&lt;blockquote&gt;&quot;Both [[Strategy Pattern]] and [[Visitor|Visitor Pattern]] do this.  These are used to combat the [[Divergent change smell]].  &quot;The fundamental rule of thumb is to put things together that change together. Data and behaviour that references that data usually change together but there are exceptions.  When the exceptions occur, we move the behavior to keep changes in one place.  Strategy and Visitor allow you to change behavior easily, because they isolate the small amount of behavior that needs to be overridden, at the cost of further indirection.&quot; [[Martin Fowler 1999]]&lt;/blockquote&gt;
  
 
== See Also ==
 
== See Also ==

Revision as of 06:23, 24 November 2010


The feature envy smell is present when a class or a method or methods from that class use methods from another class excessively, in particular if a method seems more 'interested' in another class than its own. The most common focus of the envy is the data. This is a good sign that some refactoring should be applied.

Discretion still needs to be applied since particular library methods may get used a lot, but this doesn't necessarily mean we should try to refactor around this.

Refactoring Methods

  • Move Method - if a particular method is using methods from another class excessively, move it to that class
  • Extract Method - if only a part of a method is envious
  • Extract Class - if several methods are envious and they don't belong in the envied class either

Opposing forces

Martin Fowler (Refactoring : improving the design of existing code noted that there are some patterns that break this rule:<blockquote>"Both Strategy Pattern and Visitor Pattern do this. These are used to combat the Divergent change smell. "The fundamental rule of thumb is to put things together that change together. Data and behaviour that references that data usually change together but there are exceptions. When the exceptions occur, we move the behavior to keep changes in one place. Strategy and Visitor allow you to change behavior easily, because they isolate the small amount of behavior that needs to be overridden, at the cost of further indirection." Martin Fowler 1999</blockquote>

See Also


Personal tools