当前位置: 首页 > news >正文

临沂网站建设报价生活常识网站源码

临沂网站建设报价,生活常识网站源码,网站怎么拿百度收入,wordpress 访客装饰模式#xff0c;动态地给一个对象添加一些额外的职责。就增加功能来说#xff0c;Decorator模式相比生成子类更为灵活。 13.1.解释 main()#xff0c;老爸 ISchoolReport#xff0c;成绩单接口 CFourthGradeSchoolReport#xff0c;四年级成绩单 ReportDecorator…装饰模式动态地给一个对象添加一些额外的职责。就增加功能来说Decorator模式相比生成子类更为灵活。 13.1.解释 main()老爸 ISchoolReport成绩单接口 CFourthGradeSchoolReport四年级成绩单 ReportDecorator成绩单装饰器基类 HighScoreDecorator最高分装饰器 SortDecorator班级排名装饰器 说明对“四年级成绩单”进行装饰ReportDecorator必然有一个private变量指向ISchoolReport。 注意 看代码 // Decorator.cpp//主程序#include stdafx.h#include ISchoolReport.h#include FouthGradeSchoolReport.h#include SugarFouthGradeSchoolReport.h#include HighScoreDecorator.h#include SortDecorator.h#include iostreamusing std::cout;using std::endl;void DoIt(){    ISchoolReport *psr new CSugarFouthGradeSchoolReport();    psr-Report();//看成绩单    psr-Sign(老三);//很开心就签字了    delete psr;}void DoNew(){    cout ----------分部分进行装饰---------- endl;    ISchoolReport *psr new CFouthGradeSchoolReport();//原装成绩单    //    ISchoolReport *pssr new CSortDecorator(psr);//又加了成绩排名的说明    ISchoolReport *phsr new CHighScoreDecorator(pssr);//加了最高分说明的成绩单    phsr-Report();//看成绩单    phsr-Sign(老三);//很开心就签字了        //先装饰哪个不重要顺序已经在装饰内部确定好但一定要调用最后一个装饰器的接口。    //ISchoolReport *phsr new CHighScoreDecorator(psr);//加了最高分说明的成绩单    //ISchoolReport *pssr new CSortDecorator(phsr);//又加了成绩排名的说明    //pssr-Report();//看成绩单    //pssr-Sign(老三);//很开心就签字了    delete pssr;    delete phsr;    delete psr;}int _tmain(int argc, _TCHAR* argv[]){    //在装饰之前可以用继承的办法来进行简单的修饰    DoIt();    //但如果需要修饰的项目太多呢或者装饰的项目不是固定的继承显然会变得更复杂    DoNew();    _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF | _CRTDBG_ALLOC_MEM_DF);    _CrtDumpMemoryLeaks();    return 0;} //ISchoolReport.h #pragma once#include iostreamusing std::string;class ISchoolReport{public:    ISchoolReport(void)    {    }    virtual ~ISchoolReport(void)    {    }    virtual void Report() 0;    virtual void Sign(string name) 0;}; //FouthGradeSchoolReport.h #pragma once#include ischoolreport.hclass CFouthGradeSchoolReport :    public ISchoolReport{public:    CFouthGradeSchoolReport(void);    ~CFouthGradeSchoolReport(void);    void Report();    void Sign(string name);}; //FouthGradeSchoolReport.cpp #include StdAfx.h#include FouthGradeSchoolReport.h#include iostreamusing std::cout;using std::endl;using std::string;CFouthGradeSchoolReport::CFouthGradeSchoolReport(void){}CFouthGradeSchoolReport::~CFouthGradeSchoolReport(void){}void CFouthGradeSchoolReport::Report(){    cout 尊敬的XXX家长 endl;    cout ...... endl;    cout 语文62  数学65  体育98  自然63 endl;    cout ...... endl;    cout                 家长签名 endl;}void CFouthGradeSchoolReport::Sign(string name){    cout 家长签名为 name.c_str() endl;} //ReportDecorator.h #pragma once#include ischoolreport.hclass CReportDecorator :    public ISchoolReport{public:    CReportDecorator(ISchoolReport *psr);    virtual ~CReportDecorator(void);    void Report();    void Sign(string name);private:    ISchoolReport *m_pSchoolReport;}; //ReportDecorator.cpp #include StdAfx.h#include ReportDecorator.h#include iostreamusing std::string;CReportDecorator::CReportDecorator(ISchoolReport *psr){    this-m_pSchoolReport psr;}CReportDecorator::~CReportDecorator(void){}void CReportDecorator::Report(){    this-m_pSchoolReport-Report();}void CReportDecorator::Sign( string name ){    this-m_pSchoolReport-Sign(name);} //HighScoreDecorator.h #pragma once#include reportdecorator.h#include ISchoolReport.hclass CHighScoreDecorator :    public CReportDecorator{public:    CHighScoreDecorator(ISchoolReport *psr);    ~CHighScoreDecorator(void);    void Report();private:    void ReportHighScore();}; //HighScoreDecorator.cpp #include StdAfx.h#include HighScoreDecorator.h#include iostreamusing std::cout;using std::endl;CHighScoreDecorator::CHighScoreDecorator( ISchoolReport *psr ) : CReportDecorator(psr){}CHighScoreDecorator::~CHighScoreDecorator(void){}void CHighScoreDecorator::Report(){    this-ReportHighScore();    this-CReportDecorator::Report();}void CHighScoreDecorator::ReportHighScore(){    cout 这次考试语文最高是75 数学是78 自然是80 endl;} //SortDecorator.h #pragma once#include reportdecorator.h#include ISchoolReport.hclass CSortDecorator :    public CReportDecorator{public:    CSortDecorator(ISchoolReport *psr);    ~CSortDecorator(void);    void Report();private:    void ReportSort();};//SortDecorator.cpp #include StdAfx.h#include SortDecorator.h#include iostreamusing std::cout;using std::endl;CSortDecorator::CSortDecorator( ISchoolReport *psr ) : CReportDecorator(psr){}CSortDecorator::~CSortDecorator(void){}void CSortDecorator::ReportSort(){    cout 我是排名第38名... endl;}void CSortDecorator::Report(){    this-CReportDecorator::Report();    this-ReportSort();} 这也是一个比较简单的模式属于行为型模式。 转载于:https://www.cnblogs.com/wanggary/archive/2011/04/18/2020254.html
http://www.zqtcl.cn/news/29546/

相关文章:

  • 第一免费营销型网站wordpress 上传 中文
  • 甘肃省建设工程安全质量监督管理局网站官网长尾词挖掘工具
  • 内部券网站怎么做教育培训网站模板下载
  • 科技公司网站首页搜狗搜索网
  • 福州网站建设询q479185700上快seo优化思路
  • 手工制作网站wordpress+信息查询
  • 专门做潮搭的网站库存管理软件手机版
  • 超炫网站常用小网站
  • 制作一个购物网站WordPress 黛米付
  • 有没有一种网站做拍卖厂的做信息网站怎么赚钱
  • 网站这么做wordpress绑定二级域名
  • 滕州市 网站建设公司阿里云与wordpress
  • 餐饮公司加盟网站建设免费手机网站自助建站
  • 互动营销型网站建设做淘宝客的网站怎么备案
  • 优化算法 网站微信小程序的推广方式
  • 河北网站建设多少钱可以直接玩游戏的网址
  • wordpress网站欣赏南宁手机平台网站建设
  • 市政浙江建设培训中心网站微信运营是什么样的岗位
  • wordpress图片点击seo搜索引擎优化试题
  • 网站备案需要营业执照吗企业小程序建设公司
  • 建站免费加盟万站霸屏
  • 商城类网站如何做seo企业网络营销推广方案
  • 个人房屋做民宿在哪个网站seo与sem的区别与联系
  • 军事网站大全军事网vs做网站开发吗
  • seo怎么给网站做外链手机广告推广软件
  • 烟台建站价格js怎么做网页
  • 网站会员充值接口怎么做的郑州网站制作方案报价
  • 如何制作响应式网站青秀区网站建设
  • 网站的加盟代理网站建设公司市场
  • 加强机关门户网站建设免费行情软件app网站直播下载