zoukankan      html  css  js  c++  java
  • 适配器模式

    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();
            }
        }
    }

  • 相关阅读:
    MySQL 函数
    ARC072_F Dam
    1373D
    科目二和科目三找准30厘米位置的点位
    MySQL 数字保留两位小数
    IntelliJ IDEA 中,项目文件右键菜单没有svn选项解决办法
    MySQL SQL语句书写顺序和执行顺序
    科目三道路驾驶技能考试之百米加减挡操作
    上海科目三道路驾驶技能考试夜间灯光模拟操作
    上海 科目三大路考试攻略
  • 原文地址:https://www.cnblogs.com/cuipengfei/p/1264829.html
Copyright © 2011-2022 走看看