C#设计模式之外观模式介绍
时间:2023-03-15 06:22:31
1、在设计初期阶段,应该要有意识的将不同的两层分离,比如考虑数据访问层、业务逻辑层、表示层之间建立外观模式,这样可以为子系统提供简单一致的接口,使得耦合大大降低。
2、开发阶段,子系统内部由于不够重构变得非常复杂,增加外观模式可以屏蔽这个复杂性,并提供简单的接口。
3、维护一个遗留的大型系统,代码不好再维护时,使用外观模式也是不错的选择。
看看外观模式的结构图:
Facade类定义:可以给高层系统提供简单的接口
class Facade
{
SubSystemOne one;
SubSystemTwo two;
SubSystemThree three;
SubSystemFour four;
public Facade()
{
one = new SubSystemOne();
two = new SubSystemTwo();
three = new SubSystemThree();
four = new SubSystemFour();
}
public void MethodA()
{
Console.WriteLine("MethodA组合方法");
one.MethodOne();
two.MethodOne();
}
public void MethodB()
{
Console.WriteLine("MethodB组合方法");
three.MethodOne();
four.MethodOne();
}
}
SubSystemOne 类: 底层系统会被Facade类整合简单的接口
class SubSystemOne
{
public void MethodOne()
{
Console.WriteLine("子系统方法一");
}
}
主函数调用:
class Program
{
static void Main(string[] args)
{
Facade facade = new Facade();
facade.MethodA();
facade.MethodB();
Console.ReadKey();
}
}
标签:外观模式
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
java环境变量path和classpath的配置
2023-08-31 01:09:04
![](https://img.aspxhome.com/file/2023/5/58205_0s.jpg)
C# TcpClient网络编程传输文件的示例
2021-10-16 16:01:13
![](https://img.aspxhome.com/file/2023/2/81062_0s.jpg)
Android获取手机的版本号等信息的代码
2021-09-21 06:00:26
java压缩zip文件中文乱码问题解决方法
2022-12-20 11:14:25
在Java代码中解析html,获取其中的值方法
2023-12-04 20:13:41
![](https://img.aspxhome.com/file/2023/7/125317_0s.jpg)
SpringBoot拦截器的使用
2023-04-27 23:27:27
![](https://img.aspxhome.com/file/2023/7/91077_0s.png)
Android用tabhost实现 界面切换,每个界面为一个独立的activity操作
2021-11-09 11:22:26
详解maven配置多仓库的方法示例
2021-06-10 14:13:22
![](https://img.aspxhome.com/file/2023/2/90972_0s.png)
SpringBoot2.x过后static下的静态资源无法访问的问题
2023-07-07 00:21:09
![](https://img.aspxhome.com/file/2023/3/67623_0s.jpg)
一篇文章带你入门Java基本概念
2023-11-26 01:17:08
![](https://img.aspxhome.com/file/2023/8/60318_0s.png)
Fluent Mybatis零xml配置实现复杂嵌套查询
2022-02-03 19:34:32
![](https://img.aspxhome.com/file/2023/9/71859_0s.png)
Spring Boot使用profile如何配置不同环境的配置文件
2023-11-25 12:52:36
![](https://img.aspxhome.com/file/2023/2/59932_0s.png)
Springboot WebFlux集成Spring Security实现JWT认证的示例
2021-06-02 03:24:50
C#使用List类实现动态变长数组的方法
2022-11-30 03:44:35
Unity实现场景加载功能
2021-09-15 12:27:45
![](https://img.aspxhome.com/file/2023/5/94565_0s.jpg)
Android进程间大数据通信LocalSocket详解
2023-05-21 04:21:23
解决IDEA maven 项目修改代码不生效,mvn clean、install后才生效
2022-06-19 12:17:06
![](https://img.aspxhome.com/file/2023/2/97812_0s.jpg)
Java利用自定义注解、反射实现简单BaseDao实例
2022-09-06 05:29:30
![](https://img.aspxhome.com/file/2023/5/125255_0s.png)
Java ThreadLocal类应用实战案例分析
2022-07-11 19:04:36
通过Java带你了解网络IO模型
2022-12-25 10:59:22
![](https://img.aspxhome.com/file/2023/7/72607_0s.png)