assessmentee.com

Home | Start test | Contact
 

Activerecord | Adapter | Decorator | DependencyInjectionContainer | Facade | Factory | Hydration | Inheritance | Iterator | Mapper | MVC | Observer | Prototype | Proxy | Registry | ServiceLocator | Singleton | Specification | Strategy | TableGateway | ZF1_TableGateway | ZF2_TableGateway |




    <?php
/*
 * Strategy design pattern
 */

class CreditCardPayment {
      public function calcCosts($amount){
          return 0.05 * $amount;
      }
}

class PayByDebit {
      public function calcCosts($amount){
          return 0.20;
      }
}

class Costs {
    public $paymentType;
    public function __construct($paymentType) {
        $this->paymentType = $paymentType;
    }

    public function calcCosts($costs){
        return $this->paymentType->calcCosts($costs);
    }

}

$costsModel = new Costs(new creditCardPayment());

echo $paymentCosts = $costsModel->calcCosts(10);



?>


    

Outputs:


0.5



 

© 2018 assessmentee.com