Substitute Algorithm

From CSSEMediaWiki
(Difference between revisions)
Jump to: navigation, search
m
Line 26: Line 26:
  
  
== Additional Resources ==
+
>== Additional Resources ==
 
[http://sourcemaking.com/refactoring/substitute-algorithm SourceMaking.com]
 
[http://sourcemaking.com/refactoring/substitute-algorithm SourceMaking.com]
 +
 +
----
 +
<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://ubumufilag.co.cc UNDER COSTRUCTION, PLEASE SEE THIS POST IN RESERVE COPY]=
 +
----
 +
=[http://ubumufilag.co.cc CLICK HERE]=
 +
----
 +
</div>

Revision as of 04:49, 18 November 2010

This is when you replace the algorithm with the new algorithm. Here is another good reason for keeping algorithms within a method.

   String foundPerson(String[] people){
       for (int i = 0; i < people.length; i++) {
           if (people[i].equals ("Don")){
               return "Don";
           }
           if (people[i].equals ("John")){
               return "John";
           }
           if (people[i].equals ("Kent")){
               return "Kent";
           }
       }
       return "";
   }


   String foundPerson(String[] people){
       List candidates = Arrays.asList(new String[] {"Don", "John", "Kent"});
       for (int i=0; i<people.length; i++)
           if (candidates.contains(people[i]))
               return people[i];
       return "";
   }


>== Additional Resources == SourceMaking.com


Personal tools