设计模式之Facade---外观模式

简介:

Facade---外观模式:

1,在设计初期阶段,应该有意识的将不同的层分离。

2,在开发阶段,增加FACADE可以减少类的接口之间的依赖。

3,在维护遗留的大型系统时,为新系统开发一个外观类,让新系统与外观类交互,外观与遗留代码交互所有复杂的工作。

复制代码
 1 /*
 2  * Created by SharpDevelop.
 3  * User: home
 4  * Date: 2013/4/24
 5  * Time: 22:18
 6  * 
 7  * To change this template use Tools | Options | Coding | Edit Standard Headers.
 8  */
 9 using System;
10 
11 namespace Facade
12 {
13     class Stock
14     {
15         public void Sell()
16         {
17             Console.WriteLine("股票卖出");
18         }
19         public void Buy()
20         {
21             Console.WriteLine("投票买入");
22         }
23     }
24     
25     class NationDebt
26     {
27         public void Sell()
28         {
29             Console.WriteLine("国债卖出");
30         }
31         public void Buy()
32         {
33             Console.WriteLine("国债买入");
34         }
35     }
36     
37     class Realty
38     {
39         public void Sell()
40         {
41             Console.WriteLine("地产卖出");
42         }
43         public void Buy()
44         {
45             Console.WriteLine("地产买入");
46         }
47     }
48     
49     class Fund
50     {
51         Stock st;
52         NationDebt nd;
53         Realty re;
54         
55         public Fund()
56         {
57             st = new Stock();
58             nd = new NationDebt();
59             re = new Realty();
60         }
61         public void BuyFund()
62         {
63             st.Buy();
64             nd.Buy();
65             re.Buy();
66         }
67         public void SellFund()
68         {
69             st.Sell();
70             nd.Sell();
71             re.Sell();
72         }
73     }
74     
75     class Program
76     {
77         public static void Main(string[] args)
78         {
79             Fund jijin = new Fund();
80             jijin.BuyFund();
81             Console.WriteLine("========");
82             jijin.SellFund();
83             
84             Console.ReadKey(true);
85         }
86     }
87 }
复制代码

目录
相关文章
|
2月前
|
设计模式 API 数据安全/隐私保护
探索设计模式的魅力:外观模式简化术-隐藏复杂性,提供简洁接口的设计秘密
外观模式是一种关键的设计模式,旨在通过提供一个简洁的接口来简化复杂子系统的访问。其核心价值在于将复杂的内部实现细节封装起来,仅通过一个统一的外观对象与客户端交互,从而降低了系统的使用难度和耦合度。在软件开发中,外观模式的重要性不言而喻。它不仅能够提高代码的可读性、可维护性和可扩展性,还能促进团队间的协作和沟通。此外,随着业务需求和技术的发展,外观模式能够适应变化,通过修改外观对象来灵活调整客户端与子系统之间的交互方式。总之,外观模式在软件设计中扮演着举足轻重的角色,是构建高效、稳定且易于维护的软件系统的关键
76 1
探索设计模式的魅力:外观模式简化术-隐藏复杂性,提供简洁接口的设计秘密
|
2月前
|
设计模式 存储 uml
C++ 设计模式实战:外观模式和访问者模式的结合使用,派生类访问基类的私有子系统
C++ 设计模式实战:外观模式和访问者模式的结合使用,派生类访问基类的私有子系统
30 1
|
4月前
|
设计模式
设计模式-外观模式
设计模式-外观模式
32 0
|
4月前
|
设计模式 Go 开发工具
Golang设计模式——03外观模式
Golang设计模式——03外观模式
21 0
|
4月前
|
设计模式 Java 应用服务中间件
设计模式 -结构型模式_门面模式(外观模式) Facade Pattern 在开源软件中的应用
设计模式 -结构型模式_门面模式(外观模式) Facade Pattern 在开源软件中的应用
37 1
|
2月前
|
设计模式 uml
设计模式之外观模式
设计模式之外观模式
|
2月前
|
设计模式 应用服务中间件 智能硬件
【设计模式】外观模式
【设计模式】外观模式
|
4月前
|
设计模式 Java
聊聊Java设计模式-外观模式
外观(Facade)模式,又叫做门面模式,是一种通过为多个复杂的子系统提供一个一致的接口,使这些子系统更加容易被访问的模式。
37 1
聊聊Java设计模式-外观模式
|
4月前
|
设计模式
设计模式 | 门面模式 Facade
设计模式 | 门面模式 Facade
20 0
|
4月前
|
设计模式 前端开发 数据库
【设计模式】之外观模式
外观模式是一种简化复杂系统接口的设计模式,在前端开发中有着广泛的应用。它可以帮助我们封装复杂的子系统,并提供一个简单易用的接口给客户端。通过使用外观模式,我们可以提高代码的可维护性、可读性和扩展性。但是需要注意避免过度使用外观模式,以免造成不必要的性能问题。
42 1