桥接模式
来源:互联网 发布:编程需要的数学基础 编辑:程序博客网 时间:2024/06/05 18:35
聚合:表示一种弱的拥有关系,体现的是A对象可以包含B对象,但B对象不是A对象的一部分。
合成:表示一种强的拥有关系,体现了严格的部分与整体的关系,部分和整体的生命周期一样。
桥接模式:将抽象部分和它的实现部分分离,使他们都可以独立的变化。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace 桥接模式
{
abstract class Implementor //实现抽象
{
public abstract void Operation();
}
class ImplementorA : Implementor //具体实现
{
public override void Operation()
{
Console.WriteLine("A的实现方法");
}
}
class ImplementorB : Implementor
{
public override void Operation()
{
Console.WriteLine("B的实现方法");
}
}
class Abstraction //抽象部分
{
protected Implementor im;
public void SetIm(Implementor im)
{
this.im = im;
}
public virtual void Operation()
{
im.Operation();
}
}
class AbstractionA : Abstraction
{
public override void Operation()
{
im.Operation();
}
}
class Program
{
static void Main(string[] args)
{
Abstraction a = new AbstractionA();
a.SetIm(new ImplementorA());
a.Operation();
a.SetIm(new ImplementorB());
a.Operation();
}
}
}
- 设计模式:适配器模式,桥接模式
- 设计模式----桥接模式
- 设计模式---桥接模式
- 结构性模式-桥接模式
- 设计模式:桥接模式
- 设计模式 桥接模式
- 设计模式 - 桥接模式
- 设计模式--桥接模式
- 设计模式--桥接模式
- 设计模式 - 桥接模式
- 设计模式-桥接模式
- 设计模式 - 桥接模式
- 设计模式 - 桥接模式
- 【设计模式-桥接模式】
- 设计模式:桥接模式
- 【设计模式】----桥接模式
- 【设计模式】桥接模式
- 设计模式--桥接模式
- RHEL5.8物理机遇到Read-only file system
- iozone的使用与介绍
- 5.1-1
- FFT多项式乘法学习笔记
- rebar安装出错
- 桥接模式
- n次幂求法
- wampserver Zend Framework 2 alias环境布置
- Win7桌面移到其他磁盘方法
- android中html5页面调取系统摄像头
- zoj2812
- [C++] 使用基于范围的for循环操作string
- Unhandled event loop exception No more handles
- 直接使用Jlink仿真器下载程序至Freescale K60系列 MCU