。。。

<?php
/*
The strategy pattern defines a family of algorithms, each of which is encapsulated
and made interchangeable with other members within that family.
*/

interface PaymentStrategy {
    public function pay($amount);
}

class StripePayment implements PaymentStrategy {
    public function pay($amount) {
        echo 'StripePayment.<br/>';
    }
}

class PayPalPayment implements PaymentStrategy {
    public function pay($amount) {
        echo 'PayPalPayment.<br/>';
    }
}

class Checkout {
    private $amount;

    public function __construct($amount) {
        $this->amount = $amount;
    }

    public function capturePayment() {
        if ($this->amount > 99.99) {
            $payment = new PayPalPayment();
        } else {
            $payment = new StripePayment();
        }

        $payment->pay($this->amount);
    }
}

$checkout = new Checkout(49.99);
$checkout->capturePayment();

$checkout = new Checkout(149.99);
$checkout->capturePayment();

?>

最新文章

  1. apt-get 与 yum 的区别
  2. 解决因为I_JOB_NEXT问题导致job执行不正常,不停生成trace文件问题
  3. jq 移除包含某个字符串的类名js
  4. cycleInterpolator 循环加速器
  5. 深入理解ServletRequest与ServletResponse
  6. POJ 1573
  7. Linux_系统信息
  8. js字符串常用判断方法
  9. Android 高级UI设计笔记04:使用setDrawingCacheEnabled(boolean flag)提高绘图速度
  10. 测试用(编写优质嵌入式C程序)
  11. SGU 111.Very simple problem
  12. City Game
  13. 最受欢迎的Web开发工具
  14. Node.js之操作文件系统(二)
  15. 《认知与设计:理解UI设计准则》【PDF】下载
  16. volume_manager.go
  17. CSS预处器的了解
  18. JS_高程5.引用类型(4)Array类型的各类方法
  19. python+django+uwsgi 搭建环境
  20. LightOJ 1030 【概率DP求期望】

热门文章

  1. Python数据分析与爬虫
  2. greatest among three numbers
  3. C# HTTP系列8 GET与POST对比说明
  4. Django初见
  5. Linux搭建Nexus仓库+高可用方案
  6. Axure入门
  7. windows上redis的安装和配置
  8. [转帖]PG的时间函数使用整理如下
  9. json工具类(三)——net包
  10. 《 .NET并发编程实战》阅读指南 - 第4章