• 适配器模式


    2008年08月10日 星期日 下午 05:57

    using System;
    using System.Collections.Generic;
    using System.Text;

    namespace ConsoleApplication1
    {
        abstract class Birds
        {
            public abstract void Fly();

            public abstract void Shout();
        }

        class Duck:Birds
        {
            public override void Fly()
            {
                Console.WriteLine("鸭子飞");
            }

            public override void Shout()
            {
                Console.WriteLine("鸭子叫唤");
            }
        }

        class Chick:Birds
        {
            public override void Fly()
            {
                Console.WriteLine("小鸡飞");
            }

            public override void Shout()
            {
                Console.WriteLine("小鸡飞");
            }
        }

        class Adapter:Birds
        {
            private Eagle eagle=new Eagle();

            public override void Fly()
            {
                eagle.Fly();
            }

            public override void Shout()
            {
                eagle.Shout();
            }
        }

        class Eagle
        {
            public void Fly()
            {
                Console.WriteLine("老鹰飞");
            }

            public void Shout()
            {
                Console.WriteLine("老鹰叫唤");
            }
        }

        class Client
        {
            public static void Main()
            {
                Birds b = new Duck();
                b.Fly();
                b.Shout();
                b = new Chick();
                b.Fly();
                b.Shout();
                b = new Adapter();
                b.Fly();
                b.Shout();
                Console.Read();
            }
        }
    }

  • 相关阅读:
    Data Base Oracle 常用命令
    ASP.NET Core ASP.NET Core+MVC搭建及部署
    Hadoop 之 MapReduce 框架演变详解
    计算机网络: IP地址,子网掩码,默认网关,DNS服务器详解
    Linux系统基本网络配置之ifconfig命令
    Linux-eth0 eth0:1 和eth0.1关系、ifconfig以及虚拟IP实现介绍
    Linux 中将用户添加到组的指令
    几种常见的Shell
    常见的Shell
    Linux(CentOS6.5)下创建新用户和组,并制定用户和组ID
  • 原文地址:https://www.cnblogs.com/cuipengfei/p/1264829.html
Copyright © 2020-2023  润新知