大话设计模式之外观模式
来源:互联网 发布:料理机 鱼汤 知乎 编辑:程序博客网 时间:2024/05/17 22:11
转载地址:
http://www.cnblogs.com/xyz168/archive/2011/11/24/2262040.html
本节主要内容:1.外观模式的意图;2.UML图;3.应用举例
一、外观模式意图:为子系统中的一组接口提供一个一致的接口。这个接口定义了一个高层接口,这个接口使得这一子系统更加容易使用
Provide a unified interface to a set of interface in a subsystem.Facade defines a higher-lever interface that make the subsystem easier to use.
二、UML图
原型如左图,使用外观模式之后如右图。
三、代码示例:
应用举例:写代码中常遇见的情景:一个系统的一般的三步走:需求分析形成文档、代码编写、测试。版本发布。
AnalysisApp类
View Code
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5
6 namespace y.PatternFacade
7 {
8 class AnalysisApp
9 {
10 public void AnalysisDoc()
11 {
12 Console.WriteLine("Complete Document!");
13 }
14 }
15 }
复制代码
CodeApp类:
View Code
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5
6 namespace y.PatternFacade
7 {
8 class CodeApp
9 {
10 public void DesignCode()
11 {
12 Console.WriteLine("Complete Code!");
13 }
14 }
15 }
复制代码
TestApp类:
View Code
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5
6 namespace y.PatternFacade
7 {
8 class TestApp
9 {
10 public void TestExample()
11 {
12 Console.WriteLine("Complete Test!");
13 }
14 }
15 }
复制代码
FacadeApp类
View Code
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5
6 namespace y.PatternFacade
7 {
8 class FacadeApp
9 {
10 private AnalysisApp analysisApp;
11 private CodeApp codeApp;
12 private TestApp testApp;
13 public FacadeApp()
14 {
15 analysisApp = new AnalysisApp();
16 codeApp = new CodeApp();
17 testApp = new TestApp();
18 }
19 public void ShowApp()
20 {
21 analysisApp.AnalysisDoc();
22 codeApp.DesignCode();
23 testApp.TestExample();
24 }
25 }
26 }
复制代码
Boss类
View Code
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5
6 namespace y.PatternFacade
7 {
8 class Boss
9 {
10 public void GetAppResult()
11 {
12 FacadeApp facadeApp = new FacadeApp();
13 facadeApp.ShowApp();
14 }
15 }
16 }
复制代码
控制台
View Code
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5
6 namespace y.PatternFacade
7 {
8 class Program
9 {
10 static void Main(string[] args)
11 {
12 Console.Title = "外观模式";
13 Console.WriteLine("Press any key to exit......\r\n");
14 Boss boss = new Boss();
15 boss.GetAppResult();
16 Console.Read();
17 }
18 }
19 }
复制代码
运行结果如下:
四、源码这里下载
参考文献:http://www.dofactory.com/Patterns/PatternFacade.aspx
- 大话设计之外观模式
- 大话设计模式之外观模式
- 大话设计模式之-----外观模式
- 大话设计模式之外观模式
- 大话设计模式之外观模式
- 大话设计模式之外观模式
- 大话设计模式之外观模式
- 大话设计模式之外观模式
- <<大话设计模式>>之外观模式
- 大话设计模式读后感之外观模式
- 大话设计模式之外观模式
- 大话设计模式读书笔记之外观模式
- 《大话设计模式》之外观模式
- 大话设计模式-外观模式
- 大话设计模式-外观模式
- 大话设计模式----外观模式
- <八>读<<大话设计模式>>之外观模式
- 《大话设计模式》java实现之外观模式
- 【Android Camera】之 Preview
- C#方法
- 给部分培训学生的建议
- Mercurial与TortoiseHg使用入门教程
- 通过读取properties文件动态生成对数据库的连接
- 大话设计模式之外观模式
- Netty框架之异步事件驱动模型
- 电话号码归属地查询——利用邮编从网络上抓取地址信息(1)
- CopyOnWriteArrayList
- 大话设计模式之状态模式
- jquery easyui datagrid 分页 详解
- Netty框架之网络线程模型
- FTP 类
- 电话号码归属地查询——利用邮编从网络上抓取地址信息(2)