PHP / *** Policy Mode * * Strategy mode Applicable to you have a problem with two algorithms to solve. The choice of the solution is a decision made by the user. * This mode can also solve the multilingual / style performance of web applications ** @Author doodoo
/ *** String Replacement Rule ** This example assumes a replacement of a piece of article to provide two options * / interface replacerule {public function replace ();}
/ *** Solution One * / Class ReplaceRuleone Implements ReplaceRule {Public Function Replace () {$ SUBJECT = STR_REPLACE ("ABC", "Doodoo", "This is to replace the text! ABC"); Return $ Subject;}}}
/ *** Solution Die * / Class ReplaceRuletwo Implements ReplaceRule {public function replace ($ SUBJECT = STR_REPLACE ("abc", "panwei", "This is to replace text! ABC"); Return $ Subject;}}
/ *** Algorithm Solve Class to provide customers choose what solution to use * / Class Solve {Private $ strategy = null; public function __construct (ReplaceUle $ rule) {$ this-> Strategy = $ rule;} / ** * Substance after the replacement * / public function getContext () {RETURN $ this-> strategy-> replace ();}}
// Call the first algorithm $ SOLVE = New Solve (New ReplaceRuleone ()); $ STR = $ SOLVE-> getContext (); ECHO $ Str; Echo "
/ r / n";
// Call the second algorithm $ SOLVE = New Solve (New ReplaceRuletwo ()); $ STR = $ SOLVE-> getContext (); Echo $ Str;>>>>