Refused bequest smell

From CSSEMediaWiki
(Difference between revisions)
Jump to: navigation, search
m (Reverted edits by Ebybymic (Talk); changed back to last version by LukeRobinson)
 
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://ocavyle.co.cc UNDER COSTRUCTION, PLEASE SEE THIS POST IN RESERVE COPY]=
 
----
 
=[http://ocavyle.co.cc CLICK HERE]=
 
----
 
</div>
 
 
Subclasses inherit all the methods and data from their superclass. If a subclass doesn't want to use the stuff it inherits, this can be an indication that the class hierarchy is wrong. It can also indicate that you shouldn't be subclassing. Inheritance for implementation is a classic case where the subclass doesn't really want to use the stuff it inherits.
 
Subclasses inherit all the methods and data from their superclass. If a subclass doesn't want to use the stuff it inherits, this can be an indication that the class hierarchy is wrong. It can also indicate that you shouldn't be subclassing. Inheritance for implementation is a classic case where the subclass doesn't really want to use the stuff it inherits.
  

Latest revision as of 03:18, 25 November 2010

Subclasses inherit all the methods and data from their superclass. If a subclass doesn't want to use the stuff it inherits, this can be an indication that the class hierarchy is wrong. It can also indicate that you shouldn't be subclassing. Inheritance for implementation is a classic case where the subclass doesn't really want to use the stuff it inherits.

In some cases, a class overrides methods with no-ops which can be an indication that it is refusing the bequest of its superclasses and that you have the inheritance hierarchy wrong.

Fowler however notes that refused bequest often isn't a strong smell and can be overlooked in some cases unless it is causing problems and confusion.

This may be seen in the Composite pattern where the leaf has no-op methods.

See also


Personal tools