欢迎来到装配图网! | 帮助中心 装配图网zhuangpeitu.com!
装配图网
ImageVerifierCode 换一换
首页 装配图网 > 资源分类 > DOCX文档下载
 

设计模式解析 第二版

  • 资源ID:154871142       资源大小:47.02KB        全文页数:65页
  • 资源格式: DOCX        下载积分:35积分
快捷下载 游客一键下载
会员登录下载
微信登录下载
三方登录下载: 微信开放平台登录 支付宝登录   QQ登录   微博登录  
二维码
微信扫一扫登录
下载资源需要35积分
邮箱/手机:
温馨提示:
用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)
支付方式: 支付宝    微信支付   
验证码:   换一换

 
账号:
密码:
验证码:   换一换
  忘记密码?
    
友情提示
2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

设计模式解析 第二版

设计模式解析(C+代码)个人(上传者)简述一Resources > Design Patterns Explained C+ Code Examples - Chapter 4: A Standard Object-Oriented Solution资源> 设计模式实例解释了 C+代码第四章:一个标准的面向对象的解决方案Example 4-1: Instantiating the V1 Features例 4:实例化的特征。V1TOCTOCModel模型V1ModelV1ModelFeature 特征V1V1本人第一次软件设计师考试失利,但是我没有放弃,也没有气馁因为我觉得是自己的基础不扎实,所 以我还在努力学习,设计模式是非常重要的一门学科,所以我们都得学好它。.Example 4-2: Implementation of V1 Methods 例 4:实施 V1 方法TOCTOC CutoutFeatureCutoutFeature HoleFeatureHoleFeature IrregularFeatureIrregularFeature SlotFeatureSlotFeature SpecialFeatureSpecialFeature V1CutoutV1Cutout V1HoleV1Hole V1IrregularV1Irregular V1SlotV1Slot V1SpecialV1SpecialExample 4-3: Instantiating the V2 Features 例 4:实例化 V2 飞弹的特点 TOCTOC V2ModelV2Model V2CutoutV2Cutout V2HoleV2Hole V2IrregularV2Irregular V2SpecialV2Special OOGFeatureOOGFeatureExample 4-4: Implementation of V2 Methods 例子:实施中 V2 的方法TOCTOC V2SlotV2SlotModel模型V1ModelV1ModelFeature 特征V1V1Example 4-1: Instantiating the V1 Features例 4:实例化的特征。V1Model模型TOP最高Model.hModel.h#pragma once#include "Feature.h”class Modelpublic:Model(void);protected:Feature *features;int nElements;public:virtual Model(void);Model.cppModel.cpp#include "Model.h”Model:Model(void)Model:Model(void)V1ModelV1ModelTOP最高V1Model.hV1Model.h#pragma once#include "model.h”#include <string>using namespace std;class V1Model : public Modelpublic:Model(void);static int openModel( string ModelName);static Model* buildV1Model(string);void buildModel();private:void buildV1Model();int nElements;int myModelNumber;int getNumberOfElements();public:V1Model(void);V1Model.cppV1Model.cpp #include "VIModel.h”#include "Feature.h”#include "Vl.h”#include "VlSlot.h”#include "VlHole.h”V1Model:V1Model(void)V1Model:V1Model(void)/ segment of code that instantiates the features/ no error checking providedfor illustration/ purposes onlyModel* V1Model:buildV1Model (string modelName)int modNum;modNum= V1Model:openModel( modelName);if (modNum <= 0) return 0l;V1Model *myModel= new V1Model;myModel->myModelNumber= modNum;myModel->buildModel();return myModel;void V1Model:buildModel()/ each feature object needs to know the model number/ and feature ID it corresponds to in order to/ retrieve information when requested. Note how/ this information is passed to each objects/ constructornElements= getNumberOfElements();features= new Feature* nElements;/ do for each feature in the modelint i;int ID;for (i= 0; i < nElements; i+)/ determine feature present and create/ appropriate feature objectID= V1:getFeatureID( myModelNumber, i);switch( V1:getFeatureType( myModelNumber, ID)case FEATURE_SLOT:featuresi= new V1Slot( myModelNumber, ID); break;case FEATURE_HOLE:featuresi= new V1Hole( myModelNumber, ID); break;/ Other casesint V1Model:getNumberOfElements ()/ get the number of Elements from V1/ for code example, just return 1;return 1;Feature 特征TOP最高Feature.hFeature.h#pragma once#include "definitions.h”#include <string> using namespace std;class Featurepublic:Feature(void);public:virtual Feature(void);Feature.cppFeature.cpp#include "Feature.h”Feature:Feature(void)Feature:Feature(void)V1V1TOP最高Vl.hVl.h#pragma once#include "definitions.h”class V1public:V1(void);static FEATURE_TYPES getFeatureType( int, int);static int getFeatureID( int, int );static double getXforHole( int, int);static double getX1forSlot( int, int);static double getX2forSlot( int, int);public:V1(void);V1.cppV1.cpp#include V1.hV1:V1(void)V1:V1(void)double V1:getXforHole( int, int)return 0;double V1:getX1forSlot( int, int)return 0;double V1:getX2forSlot( int, int)return 0;Example 4-2: Implementation of V1 Methods 例 4:实施 V1 方法 CutoutFeatureCutoutFeature HoleFeatureHoleFeature IrregularFeatureIrregularFeature SlotFeatureSlotFeature SpecialFeatureSpecialFeature V1CutoutV1Cutout V1HoleV1Hole V1IrregularV1Irregular V1SlotV1Slot V1SpecialV1SpecialCutoutFeatureCutoutFeatureTOP最高CutoutFeature.hCutoutFeature.h#pragma once#include "feature.h” class CutoutFeature :public Feature public:CutoutFeature(void);public:CutoutFeature(void);;CutoutFeature.cppCutoutFeature.cpp#include "CutoutFeature.h”CutoutFeature:CutoutFeature(void)CutoutFeature:CutoutFeature(void)HoleFeatureHoleFeatureTOP最高HoleFeature.hHoleFeature.h#pragma once#include "feature.h”class HoleFeature :public Featurepublic:HoleFeature(void);public:HoleFeature(void);HoleFeature.cppHoleFeature.cpp#include "HoleFeature.h”HoleFeature:HoleFeature(void)HoleFeature:HoleFeature(void)IrregularFeatureIrregularFeatureTOP最高IrregularFeature.hIrregularFeature.h#pragma onceclass IrregularFeaturepublic:IrregularFeature(void);public:virtual IrregularFeature(void);;IrregularFeature.cppIrregularFeature.cpp#include "IrregularFeature.h”IrregularFeature:IrregularFeature(void)IrregularFeature:IrregularFeature(void)SlotFeatureSlotFeatureTOP最高SlotFeature.hSlotFeature.h#pragma once#include "feature.h”class SlotFeature :public Featurepublic:SlotFeature(void);public:SlotFeature(void);SlotFeature.cppSlotFeature.cpp#include "SlotFeature.h”SlotFeature:SlotFeature(void)SlotFeature:SlotFeature(void)SpecialFeatureSpecialFeatureTOP最高SpecialFeature.hSpecialFeature.h#pragma once#include "feature.h”class SpecialFeature :public Featurepublic:SpecialFeature(void);public:SpecialFeature(void);;SpecialFeature.cppSpecialFeature.cpp#include "SpecialFeature.h”SpecialFeature:SpecialFeature(void)SpecialFeature:SpecialFeature(void)V1CutoutV1CutoutTOP最高V1Cutout.hV1Cutout.h#pragma once#include "cutoutfeature.h”class V1Cutout :public CutoutFeaturepublic:V1Cutout(int, int);public:V1Cutout(void);private:int myModelNumber;int myID;V1Cutout.cppV1Cutout.cpp#include V1Cutout.hV1Cutout:V1Cutout(int modelNumber, int ID) myModelNumber = modelNumber;myID = ID;V1Cutout:V1Cutout(void)V1HoleV1HoleTOP最高V1Hole.hV1Hole.h#pragma once#include "holefeature.h class V1Hole :public HoleFeature public:V1Hole(int, int);double getX();public:V1Hole(void);private:int myModelNumber;int myID;V1Hole.cppV1Hole.cpp#include V1Hole.h#include V1.hV1Hole:V1Hole(int modelNumber, int ID)myModelNumber = modelNumber;myID = ID;V1Hole:V1Hole(void)/ myModelNumber and myID are private members containing/ information about the model and feature (in V1) this/ feature corresponds todouble V1Hole:getX()return V1:getXforHole( myModelNumber, myID);V1IrregularV1IrregularTOP最高V1Irregular.hV1Irregular.h#pragma once#include "irregularfeature.h”class V1Irregular :public IrregularFeaturepublic:V1Irregular(int, int);public:V1Irregular(void);private:int myModelNumber;int myID;V1Irregular.cppV1Irregular.cpp#include V1Irregular.hV1Irregular:V1Irregular(int modelNumber, int ID) myModelNumber = modelNumber;myID = ID;V1Irregular:V1Irregular(void)V1SlotV1SlotTOP最高V1Slot.hV1Slot.h#pragma once#include "slotfeature.h”class V1Slot :public SlotFeaturepublic:V1Slot(int, int);double getX1();double getX2();public:V1Slot(void);private:int myModelNumber;int myID;V1Slot.cppV1Slot.cpp#include V1Slot.h#include V1.hV1Slot:V1Slot(int modelNumber, int ID)myModelNumber = modelNumber;myID = ID;V1Slot:V1Slot(void)/ myModelNumber and myID are private members containing/ information about the model and feature (in V1) this/ feature corresponds todouble V1Slot:getX1 ()return V1:getX1forSlot( myModelNumber, myID);double V1Slot:getX2 ()return V1:getX2forSlot( myModelNumber, myID);V1SpecialV1SpecialTOP最高V1Special.hV1Special.h#pragma once#include "specialfeature.h”class VISpecial :public SpecialFeaturepublic:V1Special(int, int);public:V1Special(void);private:int myModelNumber;int myID;V1Special.cppV1Special.cpp#include V1Special.hV1Special:V1Special(int modelNumber, int ID)myModelNumber = modelNumber;myID = ID;V1Special:V1Special(void)Example 4-3: Instantiating the V2 Features 例 4:实例化 V2 飞弹的特点 V2ModelV2Model V2CutoutV2Cutout V2HoleV2Hole V2IrregularV2Irregular V2SpecialV2Special OOGFeatureOOGFeatureV2ModelV2ModelTOP最高V2Model.hV2Model.h#pragma once#include "model.h”#include <string> using namespace std;#include "OOGFeature.h”#include "definitions.h” class V2Model :public Modelpublic:V2Model(void);static int openModel( string ModelName);static Model* buildV2Model(string);void buildModel();int getNumberOfElements();OOGFeature *getElement(int);public:V2Model(void);V2Model.cppV2Model.cpp#include V2Model.h#include V2Slot.h#include V2Hole.hV2Model:V2Model(void)V2Model:V2Model(void)/ segment of code that instantiates the features/ no error checking providedfor illustration/ purposes onlyModel* V2Model:buildV2Model (string modelName)/ open modelint modNum;modNum= V2Model:openModel( modelName);if (modNum <= 0) return 0l;V2Model *myModel= new V2Model;if (!myModel->openModel( modelName) return 0l;myModel->buildModel();return myModel;void V2Model:buildModel()/ each feature object needs to know the feature in the/ V2 system it corresponds to in order to retrieve/ information when requested. Note how this information/ is passed into each objects constructornElements= getNumberOfElements();OOGFeature *oogF= new OOGFeature;/ do for each feature in the model int i;for (i= 0; i < nElements; i+) / determine feature present and create/ appropriate feature objectoogF= getElement(i);switch( oogF->getType()case OOGFEATURE_SLOT:featuresi= new V2Slot( oogF); break;case OOGFEATURE_HOLE:featuresi= new V2Hole( oogF); break;/ other casesint V2Model:getNumberOfElements ()/ get the number of Elements from V1/ for code example, just return 1;return 1;V2CutoutV2CutoutTOP最高V2Cutout.hV2Cutout.h#pragma once#include "cutoutfeature.h”#include "OOGFeature.h”class V2Cutout :public CutoutFeaturepublic:V2Cutout(OOGFeature *feature);public:V2Cutout(void);private:OOGFeature *myOOGFeature;V2Cutout.cppV2Cutout.cpp#include V2Cutout.h#include "OOGFeature.h”V2Cutout:V2Cutout(OOGFeature *feature)myOOGFeature= feature;V2Cutout:V2Cutout(void)V2HoleV2HoleTOP最高V2Hole.hV2Hole.h#pragma once#include "holefeature.h”#include "OOGFeature.h”class V2Hole :public HoleFeaturepublic:V2Hole(OOGFeature *feature);double getX();public:V2Hole(void);private:OOGFeature *myOOGFeature;V2Hole.cppV2Hole.cpp#include V2Hole.h#include "OOGFeature.h”V2Hole:V2Hole(OOGFeature *feature)myOOGFeature= feature;V2Hole:V2Hole(void)double V2Hole:getX ()return myOOGFeature->getX1();V2IrregularV2IrregularTOP最高V2Irregular.hV2Irregular.h#pragma once#include "irregularfeature.h”#include "OOGFeature.h” class V2Irregular :public IrregularFeaturepublic:V2Irregular(OOGFeature *feature);public:V2Irregular(void);private:OOGFeature *myOOGFeature;;V2Irregular.cppV2Irregular.cpp#include V2Irregular.h#include "OOGFeature.h”V2Irregular:V2Irregular(OOGFeature *feature)myOOGFeature= feature;V2Irregular:V2Irregular(void)V2SpecialV2SpecialTOP最高V2Special.hV2Special.h#pragma once#include "specialfeature.h”#include "OOGFeature.h”class V2Special :public SpecialFeaturepublic:V2Special(OOGFeature *feature);public:V2Special(void);private:OOGFeature *myOOGFeature;V2Special.cppV2Special.cpp#include V2Special.h#include "OOGFeature.h”V2Special:V2Special(OOGFeature *feature)myOOGFeature= feature;V2Special:V2Special(void)OOGFeatureOOGFeatureTOP最高OOGFeature.hOOGFeature.h#pragma once#include "definitions.h”class OOGFeaturepublic:OOGFeature(void);double getX1();double getX2();OOGFEATURE_TYPES getType();public:OOGFeature(void);OOGFeature.cppOOGFeature.cpp#include "OOGFeature.h”OOGFeature:OOGFeature(void)OOGFeature:OOGFeature(void)double OOGFeature:getX1()return 0;double OOGFeature:getX2()return 0;Example 4-4: Implementation of V2 Methods 例子:实施中 V2 的方法V2SlotV2SlotV2SlotV2SlotTOP最高V2Slot.hV2Slot.h#pragma once#include "slotfeature.h”#include "OOGFeature.h”class V2Slot :public SlotFeaturepublic:V2Slot(OOGFeature *feature);double getX1();double getX2();public:V2Slot(void);private:OOGFeature *myOOGFeature;V2Slot.cppV2Slot.cpp#include V2Slot.h#include "OOGFeature.h”V2Slot:V2Slot(OOGFeature *feature)myOOGFeature= feature;V2Slot:V2Slot(void)double V2Slot:getX1 ()return myOOGFeature->getX1();double V2Slot:getX2 ()return myOOGFeature->getX2();Example 7-1: Implementing the Adapter PatternTOC Shape Circle XX_CircleShapeTOPShape.h#pragma onceclass Shapepublic:Shape(void);void virtual display()= 0 public:Shape(void);Shape.cpp#include "Shape.h”Shape:Shape(void)Shape:Shape(void)CircleTOPCircle.h#pragma once#include "Shape.h”#include XX_Circle.hclass Circle : public Shapepublic:Circle(XX_Circle *xxCircle);void display();public:Circle(void);private:XX_Circle *myXX_Circle;Circle.cpp#include "Circle.h”Circle:Circle(XX_Circle *xxCircle)myXX_Circle = xxCircle;Circle:Circle(void)delete myXX_Circle;void Circle:display()myXX_Circle->displayIt();XX_CircleTOPXX_Circle.h#pragma onceclass XX_Circlepublic:XX_Circle(void);void displayIt();public:XX_Circle(void);XX_Circle.cpp#include XX_Circle.hXX_Circle:XX_Circle(void)XX_Circle:XX_Circle(void)Example 9-1: Implementing the Strategy PatternTOC TaxController SalesOrder CalcTax CanTax USTaxTaxControllerTOPTaxController.h#pragma once#include "CalcTax.h”class TaskControllerpublic:TaskController(void);void process();CalcTax *getTaxRulesForCountry();public:TaskController(void);TaxController.cpp#include "TaskController.h”#include "SalesOrder.h”#include "CalcTax.h”#include "USTax.h”TaskController:TaskController(void)TaskController:TaskController(void)void TaskController:process ()/ this code is an emulation of a/ processing task controller/ ./ figure out which country you are in CalcTax *myTax;myTax= getTaxRulesForCountry();SalesOrder *mySO= new SalesOrder();mySO->process( myTax);CalcTax *TaskController:getTaxRulesForCountry() / In real life, get the tax rules based on / country you are in. You may have the/ logic here or you may have it in a/ configuration file/ Here, just return a USTax so this / will compile.return new USTax;SalesOrderTOPSalesOrder.h#pragma once#include "CalcTax.h”class SalesOrderpublic:SalesOrder(void);void process (CalcTax *TaxToUse);public:SalesOrder(void);SalesOrder.cpp#include "SalesOrder.h”SalesOrder:SalesOrder(void)SalesOrder:SalesOrder(void)void SalesOrder:process (CalcTax *taxToUse)long itemNumber= 0;double price= 0;/ given the tax object to use/ ./ calculate taxdouble tax= taxToUse->taxAmount( itemNumber, price); CalcTaxTOPCalcTax.h#pragma onceclass CalcTaxpublic:CalcTax(void);double virtual taxAmount( long, double)= 0;public:CalcTax(void);;CalcTax.cpp#include "CalcTax.h”CalcTax:CalcTax(void)CalcTax:CalcTax(void)CanTaxTOPCanTax.h#pragma once#include "calctax.h”class CanTax :public CalcTaxpublic:CanTax(void);double taxAmount( long, double);public:CanTax(void);CanTax.cpp#include "CanTax.h”CanTax:CanTax(void)CanTax:CanTax(void)double CanTax:taxAmount (long itemSold, double price)/ in real life, figure out tax according to/ the rules in Canada and return it/ here, return 0 so this will compilereturn 0.0;USTaxTOPUSTax.h#pragma once#include "calctax.h class USTax :public CalcTax public:USTax(void);double taxAmount( long, double);public:USTax(void);USTax.cpp#include "USTax.h”USTax:USTax(void)USTax:USTax(void)double USTax:taxAmount (long itemSold, double price)/ in real life, figure out tax according to/ the rules in the US and return it/ here, return 0 so this will compilereturn 0.0;Resources > Design Patterns Explained C+ Code Examples - Chapter 10: The Bridge Pattern Example 10-1TOC Rectangle VIRectangle V2Rectangle DPI DP2Example 10-2TOC Shape Circle Rectangle VICircle VIRectangle V2Circle V2Rectangle DPI DP2Example 10-3TOC Client Factory Shape Circle Rectangle Drawing V1Drawing V2Drawing DP1 DP2Example 10-1 Rectangle V1Rectangle V2Rectangle DP1 DP2RectangleTOPRectangle.h#pragma onceclass Rectanglepublic:Rectangle(double, double, double, double);virtual void drawLine(double, double, double, double)=0;void draw();public:Rectangle(void);private:double _x1, _x2, _y1, _y2;Rectangle.cpp#include "Rectangle.h”Rectangle:Rectangle(double x1, double y1, double x2, double y2)_x1= x1; _y1= y1; _x2= x2; _y2= y2;Rectangle:Rectangle(void)void Rectangle:draw()drawLine( _x1, _y1, _x2, _y1);drawLine( _x2, _y1, _x2, _y2);drawLine( _x2, _y2, _x1, _y2);drawLine( _x1, _y2, _x1, _y1);VIRectangleTOPVIRectangle.h#pragma once#include "Rectangle.h”class V1Rectangle : public Rectanglepublic:V1Rectangle(double, double, double, double);void drawLine( double, double, double, double);public:V1Rectangle(void);VIRectangle.cpp#include V1Rectangle.h#include DP1.hV1Rectangle:V1Rectangle(double x1, double y1, double x2, double y2):Rectangle(x1, y1, x2, y2)V1Rectangle:V1Rectangle(void)void V1Rectangle:drawLine( double x1, double y1, double x2, double y2)DP1:draw_a_line( x1, y1, x2, y2);V2RectangleTOPV2Rectangle.h#pragma once#include "Rectangle.h”class V2Rectangle : public Rectanglepublic:V2Rectangle(double, double, double, double);void drawLine( double, double, double, double);public:V2Rectangle(void);V2Rectangle.cpp#include V2Rectangle.h#include DP2.hV2Rectangle:V2Rectangle(double x1, double y1, double x2, double y2):Rectangle(x1, y1, x2, y2)V2Rectangle:V2Rectangle(void)void V2Rectangle:drawLine( double x1, double y1, double x2, double y2)DP2:drawline( x1, y1, x2, y2);DPITOPDPl.h#pragma onceclass DP1public:DP1(void);static void draw_a_line( double, double, double, double);static void draw_a_circle( double, double, double);public:DP1(void);DPl.cpp#include DP1.hDP1:DP1(void)DP1:DP1(void)void DP1:draw_a_line( double x1, double y1, double x2, double y2)/ draw the linevoid DP1:draw_a_circle( double x, double y, doub

注意事项

本文(设计模式解析 第二版)为本站会员(lis****211)主动上传,装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知装配图网(点击联系客服),我们立即给予删除!

温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




关于我们 - 网站声明 - 网站地图 - 资源地图 - 友情链接 - 网站客服 - 联系我们

copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!