欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 文旅 > 文化 > 设计模式-外观模式

设计模式-外观模式

2024/10/24 1:49:54 来源:https://blog.csdn.net/qq_58870988/article/details/141139394  浏览:    关键词:设计模式-外观模式

概述

外观模式也是一种结构型的设计模式其最主要的功能就是简化接口,将复杂的子系统用简单的方法封装起来使得客户端在可以在不知道具体实现的情况下使用对应的功能,在实际的开发中,用的是非常非常多的,比如各种插件,各种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日
会场布置........
开始演出.....
检票
收拾场地......
统计收支
安排离场

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com