下午陪家人和小孩,晚上练起来。

<?php
/*
The adapter pattern allows the interface of an existing class to be used from another
interface, basically, helping two incompatible interfaces to work together by
converting the interface of one class into an interface expected by another class.
*/

class Stripe {
    public function capturePayment($amount) {
        echo $amount . " Stripe_capturePayment<br/>";
    }

    public function authorizeOnlyPayment($amount) {
        echo $amount . " Stripe_authorizeOnlyPayment<br/>";
    }

    public function cancelAmount($amount) {
        echo $amount . " Stripe_cancelAmount<br/>";
    }
}

interface PaymentService {
    public function capture($amount);
    public function authorize($amount);
    public function cancel($amount);
}

class StripePaymentServiceAdapter implements PaymentService {
    private $stripe;

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

    public function capture($amount) {
        $this->stripe->capturePayment($amount);
    }
    public function authorize($amount){
        $this->stripe->authorizeOnlyPayment($amount);
    }
    public function cancel($amount) {
        $this->stripe->cancelAmount($amount);
    }
}

$stripe = new StripePaymentServiceAdapter(new Stripe());
$stripe->authorize(49.99);
$stripe->capture(19.99);
$stripe->cancel(9.99);
?>

php适配器模式(adapter pattern)的更多相关文章

  1. 二十四种设计模式:适配器模式(Adapter Pattern)

    适配器模式(Adapter Pattern) 介绍将一个类的接口转换成客户希望的另外一个接口.Adapter模式使得原本由于接口不兼容而不能一起工作的那些类可以一起工作.示例有一个Message实体类 ...

  2. 设计模式 - 适配器模式(adapter pattern) 具体解释

    适配器模式(adapter pattern) 详细解释 本文地址: http://blog.csdn.net/caroline_wendy 适配器模式(adapter pattern): 将一个类的接 ...

  3. 乐在其中设计模式(C#) - 适配器模式(Adapter Pattern)

    原文:乐在其中设计模式(C#) - 适配器模式(Adapter Pattern) [索引页][源码下载] 乐在其中设计模式(C#) - 适配器模式(Adapter Pattern) 作者:webabc ...

  4. 【设计模式】适配器模式 Adapter Pattern

    适配器模式在软件开发界使用及其广泛,在工业界,现实中也是屡见不鲜.比如手机充电器,笔记本充电器,广播接收器,电视接收器等等.都是适配器. 适配器主要作用是让本来不兼容的两个事物兼容和谐的一起工作.比如 ...

  5. 怎样让孩子爱上设计模式 —— 7.适配器模式(Adapter Pattern)

    怎样让孩子爱上设计模式 -- 7.适配器模式(Adapter Pattern) 标签: 设计模式初涉 概念相关 定义: 适配器模式把一个类的接口变换成client所期待的还有一种接口,从而 使原本因接 ...

  6. 设计模式 - 适配器模式(adapter pattern) 枚举器和迭代器 具体解释

    适配器模式(adapter pattern) 枚举器和迭代器 具体解释 本文地址: http://blog.csdn.net/caroline_wendy 參考适配器模式(adapter patter ...

  7. 设计模式系列之适配器模式(Adapter Pattern)——不兼容结构的协调

    模式概述 模式定义 模式结构图 模式伪代码 类适配器,双向适配器,缺省适配器 类适配器 双向适配器 缺省适配器 模式应用 模式在JDK中的应用 模式在开源项目中的应用 模式总结 主要优点 主要缺点 适 ...

  8. 设计模式(七): 通过转接头来观察"适配器模式"(Adapter Pattern)

    在前面一篇博客中介绍了“命令模式”(Command Pattern),今天博客的主题是“适配器模式”(Adapter Pattern).适配器模式用处还是比较多的,如果你对“适配器模式”理解呢,那么自 ...

  9. 适配器模式(Adapter Pattern)

    适配器模式概述 定义:将一个类的接口转化成客户希望的另一个接口,适配器模式让那些接口不兼容的类可以一起工作.别名(包装器[Wrapper]模式) 它属于创建型模式的成员,何为创建型模式:就是关注如何将 ...

  10. 七个结构模式之适配器模式(Adapter Pattern)

    定义: 将一个接口转换为客户需要的另外一个接口,使接口不兼容的类型可以一起工作,也被称为包装器模式(Wrapper Patern). 结构图: Target:目标抽象类,客户所需要的接口. Adapt ...

随机推荐

  1. Web中线程与IIS线程池自动回收机制

    开发Web项目后,部署到 IIS上 ,运行一直稳定,当Web程序中加入了定时任务,或者线程之类的机制后,第二天发现悲催了,定时任务并没有执行,此时重新登录一下网站,定时任务又重新执行.原来IIS默认有 ...

  2. atlassian-confluence - docker安装

    一下内容在centos 7安装成功.一.安装docker 1.yum安装docker12 yum update # 更新yumyum install docker # yum安装docker 2.开启 ...

  3. shell(一) shell变量

    基本介绍 变量命名规范 变量名要求由字母.数字.下划线组成,尽量字母开头,有明确含义 注意:变量赋值时,等号前后不能有空格,变量名称不能和字体变量冲突 自定义变量 当前shell有效 1.定义变量 v ...

  4. MongoDB查询和sql查询的总结

    查询所有表或集合 sql   show tables mongodb    db.getCollectionNames() 删除集合或表 sql   drop table 表名 mongodb    ...

  5. 《Linux就该这么学》培训笔记_ch09_使用ssh服务管理远程主机

    <Linux就该这么学>培训笔记_ch09_使用ssh服务管理远程主机 文章最后会post上书本的笔记照片. 文章主要内容: 配置网络服务 远程控制服务 不间断会话服务 书本笔记 配置网络 ...

  6. Debug 路漫漫-09:构建CNN时维度不一致问题

    Build CNN Network 之后,运行,但是报错: ValueError: Input 0 is incompatible with layer predict_vector_conv1: e ...

  7. 原生Ajax的怎么用?

    <script> function createXMLHttpRequest() { var xmlhttp; try { //先直接创建XMLHttpRequest xmlhttp = ...

  8. zk脑裂

    一.为什么zookeeper要部署基数台服务器?二.zookeeper脑裂(Split-Brain)问题2.1.什么是脑裂?2.2.什么原因导致的?2.2.zookeeper是如何解决的?一.为什么z ...

  9. 关于AQS的一点总结

    关于AQS的一点总结 2017年03月13日 09:48:13 那只是一股逆流 阅读数:772    版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/ ...

  10. DELPHI网页开发神器UNIGUI的安装与演示

    UNIGUI安装和演示 uniGUI v1.0.0.1397(带注册机).rar在delphi10.2安装 提示:安装包可以自行在网上搜索下载,或者联系我获取都可以 这里讲下怎样安装的方法: 1)执行 ...