博客
关于我
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/

你可能感兴趣的文章
Neo4j电影关系图Cypher
查看>>
Neo4j的安装与使用
查看>>
Neo4j(1):图数据库Neo4j介绍
查看>>
Neo4j(2):环境搭建
查看>>
Neo4j(4):Neo4j - CQL使用
查看>>
NEO改进协议提案1(NEP-1)
查看>>
Neo私链
查看>>
NervanaGPU 项目使用教程
查看>>
Nerves 项目教程
查看>>
nessus快速安装使用指南(非常详细)零基础入门到精通,收藏这一篇就够了
查看>>
Nessus漏洞扫描教程之配置Nessus
查看>>
Nest.js 6.0.0 正式版发布,基于 TypeScript 的 Node.js 框架
查看>>
nested exception is org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML.
查看>>
nestesd exception is java .lang.NoSuchMethodError:com.goolge.common.collect
查看>>
nestJS学习
查看>>
net core 环境部署的坑
查看>>
NET Framework安装失败的麻烦
查看>>
Net 应用程序如何在32位操作系统下申请超过2G的内存
查看>>
Net.Framework概述
查看>>
NET3.0+中使软件发出声音[整理篇]<转>
查看>>