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

  • 相关阅读:
    css做中划线与文字排版
    修复ios上第三方输入法弹出时输入键盘盖住网页没有进行相应滚动从而盖住表单输入框的问题
    一般活动页面之类简单的背景图内容布局方式
    compass的使用
    nodejs与sqlite
    ftp命令
    shell变量详解
    Vue CLI 3 使用百度地图
    centos7中安装python3
    redis集群安装问题/usr/share/rubygems/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- redis (LoadError)
  • 原文地址:https://www.cnblogs.com/cuipengfei/p/1264829.html
Copyright © 2011-2022 走看看