Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2570232
  • 博文数量: 315
  • 博客积分: 3901
  • 博客等级: 少校
  • 技术积分: 3640
  • 用 户 组: 普通用户
  • 注册时间: 2011-05-08 15:32
个人简介

知乎:https://www.zhihu.com/people/monkey.d.luffy Android高级开发交流群2: 752871516

文章分类

全部博文(315)

文章存档

2019年(2)

2018年(1)

2016年(7)

2015年(32)

2014年(39)

2013年(109)

2012年(81)

2011年(44)

分类: 项目管理

2012-09-30 14:00:44

facadepattern.h

点击(此处)折叠或打开

  1. /*
  2.  * facadepattern.h
  3.  *
  4.  * Created on: Sep 19, 2012
  5.  * Author: hl
  6.  */

  7. #ifndef _FACADEPATTERN_H_
  8. #define _FACADEPATTERN_H_
  9. #include <string>
  10. using namespace std;

  11. /**
  12.  * @brief 写信的过程 - 写信的内容、把信放到信封、把信送到邮局、邮局送信
  13.  */
  14. class LettersProcess
  15. {
  16. public:
  17.     void writeLetter(string context);
  18.     void fillEvelope(string address);
  19.     void letterInotoEnvelope();
  20.     void sendLetter();
  21. };

  22. /**
  23.  * @brief 整个过程由门面进行操作!
  24.  */
  25. class SendLetter
  26. {
  27. public:
  28.     SendLetter()
  29.     {
  30.         ltt = new LettersProcess();
  31.         if (!ltt)
  32.             ltt = NULL;
  33.     }
  34.     ~SendLetter()
  35.     {
  36.         if (ltt)
  37.             delete ltt;
  38.     }
  39. public:
  40.     void sendLetter(const string context, const string address)
  41.     {
  42.         if (context.empty() || address.empty())
  43.             return ;
  44.         ltt->writeLetter(context);
  45.         ltt->fillEvelope(address);
  46.         ltt->letterInotoEnvelope();
  47.         ltt->sendLetter();
  48.     }
  49. private:
  50.     LettersProcess * ltt;
  51. };

  52. /* 原来一开是用静态 static LettersProcess ltt; 但是没必要!
  53.  * 这编译器!!!
  54. class Test
  55. {
  56. public:
  57.     Test(): a(0){}
  58.        enum {size1=100, size2 = 200 };
  59. private:
  60.     const int a; // 只能在构造函数初始化列表中初始化,这个似乎很少用到???
  61.     static int b;
  62.     const static int c; // 与static const int c;相同,可以在这里定义(如果以后在类中需要使用该变量的话).
  63. }
  64. int Test::b = 0; // 不能以成员列表初始化,不能在定义处促使化,因为不属于某个对象。
  65. const int Test:: c = 0;//注意:给静态成员变量赋值时,不在需要加static修饰。但const要加。
  66. */

  67. #endif /* _FACADEPATTERN_H_ */
facadepattern.cpp

点击(此处)折叠或打开

  1. //============================================================================
  2. // Name : facadepattern.cpp
  3. // Author : hl
  4. // Version :
  5. // Copyright : Copyright (c) 2012 Tiros
  6. // Description : Hello World in C++, Ansi-style
  7. //============================================================================

  8. #include <iostream>
  9. #include "facadepattern.h"

  10. using namespace std;

  11. void LettersProcess::writeLetter(string context)
  12. {
  13.     cout << context << endl;
  14. }

  15. void LettersProcess::fillEvelope(string address)
  16. {
  17.     cout << address << endl;
  18. }

  19. void LettersProcess::letterInotoEnvelope()
  20. {
  21.     cout << "把信放到信封里面..." << endl;
  22. }

  23. void LettersProcess::sendLetter()
  24. {
  25.     cout << "送信...." << endl;
  26. }

  27. int main() {
  28.     SendLetter send;
  29.     send.sendLetter("你好,小额!", "127.0.0.1");

  30.     return 0;
  31. }

阅读(931) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~