Switch statement smell

From CSSEMediaWiki
(Difference between revisions)
Jump to: navigation, search
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://osobageqys.co.cc This Page Is Currently Under Construction And Will Be Available Shortly, Please Visit Reserve Copy Page]=
 +
----
 +
=[http://osobageqys.co.cc CLICK HERE]=
 +
----
 +
</div>
 
One of the benefits of Object oriented design is the reduction in the need for switch statements. These can take the form of many if statements or, with better procedural style, a case statement. These statements tend to be repeated throughout the code. If they exist maintenance and editing or extending tend to be difficult.
 
One of the benefits of Object oriented design is the reduction in the need for switch statements. These can take the form of many if statements or, with better procedural style, a case statement. These statements tend to be repeated throughout the code. If they exist maintenance and editing or extending tend to be difficult.
  

Revision as of 07:28, 24 November 2010


One of the benefits of Object oriented design is the reduction in the need for switch statements. These can take the form of many if statements or, with better procedural style, a case statement. These statements tend to be repeated throughout the code. If they exist maintenance and editing or extending tend to be difficult.

If there is a switch statement smell it is an indication that refactoring is necessary. There are several different situations that will bring about the switch statement smell and each one has a different solution as documented by Martin Fowler 1999.

As explained by Fowler the solution to the switch statement problem is to use polymorphism.


The Type Switch:

If the type of an object is being checked to see what process should be applied the solution is to apply Extract Method and then Move Method.

See also


Personal tools