设计模式-外观模式

概述

外观模式也是一种结构型的设计模式其最主要的功能就是简化接口,将复杂的子系统用简单的方法封装起来使得客户端在可以在不知道具体实现的情况下使用对应的功能,在实际的开发中,用的是非常非常多的,比如各种插件,各种API,都是这个逻辑将复杂的功能封装起来,提供接口,调用对应的接口就可以实现对应的功能。实现看下面的例子


需求:现在需要办一场演唱会,一个演唱会公司承办,演唱会公式只需要告诉开始和结束,其它复杂的实现由具体的计划实现。

外观模式

internal class Program
{
    private static void Main(string[] args)
    {
        //演出内容初始化
        PerformancePlan PP = new PerformancePlan();
        PerformanceRehearse PR = new PerformanceRehearse();
        OfficialPerformance OP = new OfficialPerformance();
        EndOfPerformance EP = new EndOfPerformance();

        PerformanceCompany performanceCompany = new PerformanceCompany(PP, PR, OP, EP);
        performanceCompany.BegainPerformance();//开始演出
        performanceCompany.EndPerformance();//结束演出
    }

    public class PerformancePlan//演出计划
    {
        public void Cost() { Console.WriteLine("花费费用XXXXXX元"); }
        public void Time() { Console.WriteLine("演出日期:9月9日"); }
        public void Theme() { Console.WriteLine("演出主题:XXXXXX音乐会"); }
        public void Location() { Console.WriteLine("地点:天津"); }
    }
    public class PerformanceRehearse//演出排练
    {
        public void Personnel() { Console.WriteLine("人员:XX,XXX,XXX"); }
        public void RehearseTime() { Console.WriteLine("排练时间:9月8日"); }
        public void Layout() { Console.WriteLine("会场布置........"); }
    }
    public class OfficialPerformance//正式演出
    {
        public void TicketCheck() { Console.WriteLine("检票"); }
        public void Performance() { Console.WriteLine("开始演出....."); }
    }
    public class EndOfPerformance//结束演出
    {
        public void Departure() { Console.WriteLine("安排离场"); }
        public void CleanUp() { Console.WriteLine("收拾场地......"); }
        public void Statistics() { Console.WriteLine("统计收支"); }
    }

    public class PerformanceCompany //演出公司
    {
        private PerformancePlan performancePlan;
        private PerformanceRehearse performanceRehearse;
        private OfficialPerformance officialPerformance;
        private EndOfPerformance endOfPerformance;
        public PerformanceCompany(PerformancePlan PP, PerformanceRehearse PR, OfficialPerformance OP, EndOfPerformance EP)
        {
            performancePlan = PP;
            performanceRehearse = PR;
            officialPerformance = OP;
            endOfPerformance = EP;
        }
        public void BegainPerformance()//开始演出
        {
            performancePlan.Cost();
            performancePlan.Theme();
            performancePlan.Time();
            performancePlan.Location();
            performanceRehearse.Personnel();
            performanceRehearse.RehearseTime();
            performanceRehearse.Layout();
            officialPerformance.Performance();
            officialPerformance.TicketCheck();
        }
        public void EndPerformance()//结束演出
        {
            endOfPerformance.CleanUp();
            endOfPerformance.Statistics();
            endOfPerformance.Departure();
        }
    }
}

输出结果:

花费费用XXXXXX元
演出主题:XXXXXX音乐会
演出日期:9月9日
地点:天津
人员:XX,XXX,XXX
排练时间:9月8日
会场布置........
开始演出.....
检票
收拾场地......
统计收支
安排离场

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值