博客
关于我
C# 适配器模式
阅读量:361 次
发布时间:2019-03-04

本文共 1053 字,大约阅读时间需要 3 分钟。

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace 适配器模式{    class Program    {        static void Main(string[] args)        {            Target target = new Adapter();            target.Request();            Console.ReadKey();        }    }    ///     /// 定义客户端期待的接口    ///     public class Target    {        ///         /// 使用virtual修饰以便子类可以重写        ///         public virtual void Request()        {            Console.WriteLine("这是Target类的Request方法");        }    }    ///     /// 定义需要适配的类    ///     public class Adaptee    {        public void SpecificRequest()        {            Console.WriteLine("这是Adaptee类的SpecificRequest方法");        }    }    ///     /// 定义适配器    ///     public class Adapter : Target    {        // 建立一个私有的Adeptee对象        private Adaptee adaptee = new Adaptee();        ///         /// 通过重写,表面上调用Request()方法,变成了实际调用SpecificRequest()        ///         public override void Request()        {            adaptee.SpecificRequest();        }    }}

运行:

 

转载地址:http://gwgr.baihongyu.com/

你可能感兴趣的文章
MYSQL一直显示正在启动
查看>>
MySQL一站到底!华为首发MySQL进阶宝典,基础+优化+源码+架构+实战五飞
查看>>
MySQL万字总结!超详细!
查看>>
mysql中cast() 和convert()的用法讲解
查看>>
MySQL中group by 与 order by 一起使用排序问题
查看>>
mysql中having的用法
查看>>
mysql中json_extract的使用方法
查看>>
MySQL中的count函数
查看>>
MySQL中的DECIMAL类型:MYSQL_TYPE_DECIMAL与MYSQL_TYPE_NEWDECIMAL详解
查看>>
MySQL中的GROUP_CONCAT()函数详解与实战应用
查看>>
MySQL中的ON DUPLICATE KEY UPDATE详解与应用
查看>>
mysql中的rbs,SharePoint RBS:即使启用了RBS,内容数据库也在不断增长
查看>>
mysql中的undo log、redo log 、binlog大致概要
查看>>
Mysql中的using
查看>>
MySQL中的关键字深入比较:UNION vs UNION ALL
查看>>
Mysql主从不同步
查看>>
mysql主从同步及清除信息
查看>>
MySQL主从篇:死磕主从复制中数据同步原理与优化
查看>>
mysql主从配置
查看>>
MySQL之DML
查看>>