桥接模式-坦克大战-c#

概要

将抽象部分与实现部分分离,使它们都可以独立的变化。

类图

桥接模式

运行 

代码 

using System;

namespace 桥接模式
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            Client client = new Client();
            client.main();
            Console.ReadLine();
        }
    }
    interface IAction
    {
        void operation();
    }
    interface IImplementor
    {
        void operationImp();
    }
    abstract class Abstraction : IAction
    {
        protected IImplementor implementor;
        public void operation()
        {
            implementor.operationImp();
        }
    }
    class Tank: Abstraction
    {
        public void setIImplementor(IImplementor implementor)
        {
            this.implementor = implementor;
        }
    }
    class Sort : IImplementor
    {
        public void operationImp()
        {
            Console.WriteLine("发射炮弹");
        }
    }
    class Run : IImplementor
    {
        public void operationImp()
        {
            Console.WriteLine("跑");
        }
    }
    class Client
    {
        public void main()
        {
            IImplementor sort = new Sort();
            IImplementor run = new Run();
            Tank tank = new Tank();
            tank.setIImplementor(sort);
            tank.operation();
            tank.setIImplementor(run);
            tank.operation();
        }
    }
}

英语

abstraction: 
n. 抽象;提取;抽象概念;空想;心不在焉
implementor
n. 实现者; 系统
refined
adj. [油气][化工][冶] 精炼的; 精确的; 微妙的; 有教养的
concrete
adj. 混凝土的; 实在的,具体的; 有形的; vi. 凝结; vt. 使凝固; 用混凝土修筑; 
operation
n. 操作; 经营; [外科] 手术; [数][计] 运算’

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值