php桥接模式(bridge pattern)
有点通了
<?php /* The bridge pattern is used when we want to decouple a class or abstraction from its implementation, allowing them both to change independently. This is useful when the class and its implementation vary often */ interface MessagingInterface { public function send($body); } class TextMessage implements MessagingInterface { public function send($body) { echo "TextMessage > send > $body: <br/>"; } } class HtmlMessage implements MessagingInterface { public function send($body) { echo "HtmlMessage > send > $body: <br/>"; } } interface MailerInterface { public function setSender(MessagingInterface $sender); public function send($body); } abstract class Mailer implements MailerInterface { protected $sender; public function setSender(MessagingInterface $sender) { $this->sender = $sender; } } class PHPMailer extends Mailer { public function send($body) { $body .= "\n\n Set from a phpmailer ."; return $this->sender->send($body); } } class SwiftMailer extends Mailer { public function send($body) { $body .= "\n\n Set from a swiftmailer ."; return $this->sender->send($body); } } $phpMailer = new PHPMailer(); $phpMailer->setSender(new TextMessage()); $phpMailer->send('Hi!'); $swiftMailer = new SwiftMailer(); $swiftMailer->setSender(new HtmlMessage()); $swiftMailer->send('Hello!'); ?>
php桥接模式(bridge pattern)的更多相关文章
- 桥接模式(Bridge Pattern)
1,定义 桥接模式(Bridge Pattern),也称为桥梁模式,其用意是将抽象化与实现化脱耦,使得两者可以独立的变化,它可以使软件系统沿着多个方向进行变化,而又不引入额外的复杂 ...
- 乐在其中设计模式(C#) - 桥接模式(Bridge Pattern)
原文:乐在其中设计模式(C#) - 桥接模式(Bridge Pattern) [索引页][源码下载] 乐在其中设计模式(C#) - 桥接模式(Bridge Pattern) 作者:webabcd 介绍 ...
- 【设计模式】桥接模式 Bridge Pattern
开篇还是引用吕振宇老师的那篇经典的文章<设计模式随笔-蜡笔与毛笔的故事>.这个真是太经典了,没有比这个例子能更好的阐明桥接模式了,这里我就直接盗来用了. 现在市面上卖的蜡笔很多,各种型号, ...
- 二十四种设计模式:桥接模式(Bridge Pattern)
桥接模式(Bridge Pattern) 介绍将抽象部分与它的实现部分分离,使它们都可以独立地变化. 示例有一个Message实体类,对它的操作有Insert()和Get()方法,现在使这些操作的抽象 ...
- python 设计模式之桥接模式 Bridge Pattern
#写在前面 前面写了那么设计模式了,有没有觉得有些模式之间很类似,甚至感觉作用重叠了,模式并不是完全隔离和独立的,有的模式内部其实用到了其他模式的技术,但是又有自己的创新点,如果一味地认为每个模式都是 ...
- Net设计模式实例之桥接模式( Bridge Pattern)
一.桥接模式简介(Brief Introduction) 桥接模式(Bridge Pattern),将抽象部分与它的实现部分分离,使的抽象和实现都可以独立地变化. Decouple an abstra ...
- 转:设计模式-----桥接模式(Bridge Pattern)
转自:http://www.cnblogs.com/houleixx/archive/2008/02/23/1078877.html 记得看原始链接的评论. 学习设计模式也有一段时间了,今天就把我整理 ...
- 七个结构模式之桥接模式(Bridge Pattern)
问题: 当存在多个独立的变化维度时,如果仍采用多层继承结构,会急剧的增加类的个数,因此可以考虑将各个维度分类,使他们不相互影响. 定义: 将抽象部分与它的实现部分进行分离,抽象部分只保留最为本质的部分 ...
- C#设计模式——桥接模式(Bridge Pattern)
一.概述在软件开发中,我们有时候会遇上一个对象具有多个变化维度.比如对汽车对象来说,可能存在不同的汽车类型,如公共汽车.轿车等,也可能存在不同的发动机,如汽油发动机.柴油发动机等.对这类对象,可应用桥 ...
随机推荐
- [转]MySQL之——崩溃-修复损坏的innodb:innodb_force_recovery
原文 https://blog.csdn.net/l1028386804/article/details/77199194 1. mysql崩溃 --------------------------- ...
- WebGPU学习(七):学习“twoCubes”和“instancedCube”示例
大家好,本文学习Chrome->webgpu-samplers->twoCubes和instancedCube示例. 这两个示例都与"rotatingCube"示例差不 ...
- Linux搭建Nexus3.X构建maven私服
备注:linux版本: ubuntu 同时已经部署好JDK8环境 一.linux安装nexus 1.创建文件夹并进入该目录 cd /usr/local && mkdir nexus & ...
- GoLang 开山篇
GoLang 开山篇 1.Golang 的学习方向 Go语言,我们可以简单的写成Golang. 2.GoLang 的应用领域 2.1 区块链的应用开发 2.2 后台的服务应用 2.3 云计算/云服务后 ...
- 前端编程的核心问题是数据与UI的绑定
1.静态页面---静态绑定 2.js dom强修改--js重置绑定: 3.chymeleaf--预处理html+特殊语言绑定: 4.react--组建化UI.js与其他语言形式绑定
- k8s-架构中各个组件介绍
参考链接:https://github.com/opsnull/follow-me-install-kubernetes-cluster kubernetes 概述 1.kubernetes 是什么 ...
- mybatis-plus 主键自增问题
主键不自增:返回值是插入的条数 <insert id="add" parameterType="EStudent"> insert into TSt ...
- 总结:WPF中模板需要绑定父级别的ViewModel该如何处理
原文:总结:WPF中模板需要绑定父级别的ViewModel该如何处理 <ListBox ItemsSource="{Binding ClassCollection}"> ...
- java加密解密工具类
package com.founder.mrp.util; import java.nio.charset.StandardCharsets; import java.security.Key; im ...
- 如何在JIRA中有效使用关注和@提及 我正在关注的问题 提及我的问题 在仪表板上显示
如何在JIRA中有效使用关注和@提及http://bbs.51testing.com/forum.php?mod=viewthread&tid=1157043&fromuid=1530 ...