zoukankan      html  css  js  c++  java
  • 设计模式学习笔记--桥接模式

     1 using System;
     2 
     3 namespace Bridge
     4 {
     5     /// <summary> 
     6     /// 作者:bzyzhang
     7     /// 时间:2016/5/31 7:19:03 
     8     /// 博客地址:http://www.cnblogs.com/bzyzhang/
     9     /// Implementor说明:本代码版权归bzyzhang所有,使用时必须带上bzyzhang博客地址 
    10     /// </summary> 
    11     public abstract class Implementor
    12     {
    13         public abstract void Operation();
    14     }
    15 }
    View Code
     1 using System;
     2 
     3 namespace Bridge
     4 {
     5     /// <summary> 
     6     /// 作者:bzyzhang
     7     /// 时间:2016/5/31 7:20:35 
     8     /// 博客地址:http://www.cnblogs.com/bzyzhang/
     9     /// ConcreteImplementorA说明:本代码版权归bzyzhang所有,使用时必须带上bzyzhang博客地址 
    10     /// </summary> 
    11     public class ConcreteImplementorA:Implementor
    12     {
    13         public override void Operation()
    14         {
    15             Console.WriteLine("具体实现A的方法执行");
    16         }
    17     }
    18 }
    View Code
     1 using System;
     2 
     3 namespace Bridge
     4 {
     5     /// <summary> 
     6     /// 作者:bzyzhang
     7     /// 时间:2016/5/31 7:21:25 
     8     /// 博客地址:http://www.cnblogs.com/bzyzhang/
     9     /// ConcreteImplementorB说明:本代码版权归bzyzhang所有,使用时必须带上bzyzhang博客地址 
    10     /// </summary> 
    11     public class ConcreteImplementorB:Implementor
    12     {
    13         public override void Operation()
    14         {
    15             Console.WriteLine("具体实现B的方法执行");
    16         }
    17     }
    18 }
    View Code
     1 using System;
     2 
     3 namespace Bridge
     4 {
     5     /// <summary> 
     6     /// 作者:bzyzhang
     7     /// 时间:2016/5/31 7:22:21 
     8     /// 博客地址:http://www.cnblogs.com/bzyzhang/
     9     /// Abstraction说明:本代码版权归bzyzhang所有,使用时必须带上bzyzhang博客地址 
    10     /// </summary> 
    11     public abstract class Abstraction
    12     {
    13         protected Implementor implementor;
    14 
    15         public void SetImplementor(Implementor implementor)
    16         {
    17             this.implementor = implementor;
    18         }
    19 
    20         public virtual void Operation()
    21         {
    22             implementor.Operation();
    23         }
    24     }
    25 }
    View Code
     1 using System;
     2 
     3 namespace Bridge
     4 {
     5     /// <summary> 
     6     /// 作者:bzyzhang
     7     /// 时间:2016/5/31 7:24:16 
     8     /// 博客地址:http://www.cnblogs.com/bzyzhang/
     9     /// RefinedAbstraction说明:本代码版权归bzyzhang所有,使用时必须带上bzyzhang博客地址 
    10     /// </summary> 
    11     public class RefinedAbstraction:Abstraction
    12     {
    13         public override void Operation()
    14         {
    15             implementor.Operation();
    16         }
    17     }
    18 }
    View Code
     1 namespace Bridge
     2 {
     3     class Program
     4     {
     5         static void Main(string[] args)
     6         {
     7             Abstraction ab = new RefinedAbstraction();
     8 
     9             ab.SetImplementor(new ConcreteImplementorA());
    10             ab.Operation();
    11 
    12             ab.SetImplementor(new ConcreteImplementorB());
    13             ab.Operation();
    14         }
    15     }
    16 }
    View Code
  • 相关阅读:
    PAT T1001 Battle Over Cities-Hard Version
    PAT甲级2019冬季考试题解
    L3-016 二叉搜索树的结构
    PAT A1135 Is It A Red Black Tree
    PAT A1114 Family Property
    PAT A1034 Head Of Gang
    PAT A1151 LCA in Binary Tree
    什么是一揽子交易
    子公司自购买日(或合并日)开始持续计算的可辨认净资产(对母公司的价值)与购买日子公司可辨认净资产的公允价值有什么区别
    借少数股东权益,贷少数股东损益
  • 原文地址:https://www.cnblogs.com/bzyzhang/p/5544611.html
Copyright © 2011-2022 走看看