The strategy pattern use different ways to deal with different things: <?php /** * a simple strategy pattern */ class strategy{ function __construct(){ } /** * if a and b are string will call stradd function * if a and b are number will call numadd function * @param $a * @param $b * @return mix */ function add($a,$b){ if (is_string($a) && is_string($b)){ return $this->stradd($a,$b); }else if (is_numeric($a) && is_numeric($b)){ return $this->numadd($a,$b); }else{ return null; } } private function stradd($a,$b){ return $a.$b; } private function numadd($a,$b){ return $a+$b; } } $strategy = new strategy(); $str1 = 'stringone'; $str2 = 'stringtwo'; echo $strategy->add($str1,$str2); echo ' '; $num1 = 23; $num2 = 43; echo $strategy->add($num1,$num2);