版權(quán)說(shuō)明:本文檔由用戶(hù)提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
軟件設(shè)計(jì)模式(二軟件設(shè)計(jì)模式(二內(nèi)復(fù)習(xí)復(fù)習(xí):patternDesignpatternsrepresentsolutionstoproblemsthatarisewhendevelo softwarewithinaparticularcontext關(guān)于patternpatternpattern復(fù)習(xí):如何描述一個(gè)模Designpatternname,AliasesorAlsoKnownProblem,IntentorContext,RelatedExamples,Known復(fù)習(xí):creationalFactory本質(zhì):用一個(gè)virtualmethod完成創(chuàng)建過(guò)
Structural一個(gè)product族的factorymethod構(gòu)成了一個(gè)factory通過(guò)product原型來(lái)構(gòu)造product,Clone+prototype通過(guò)一個(gè)構(gòu)造算法和builder接口把構(gòu)造過(guò)程與客 單實(shí)例類(lèi)型,如何構(gòu)造這單個(gè)實(shí)例?如 這單個(gè)實(shí)例把對(duì)象的獲取過(guò)程與客
**77Adapter(一Converttheinterfaceofaclassintoanotherinterfacesexpect.Adapterletsclassesworktogethercouldn'totherwisebecause patibleSometimesatoolkitclassthat'sdesignedforreuseisn'treusableonlybecauseitsinterfacedoesn'tmatchthe-specificinterfaceanapplicationrequires.Adapter模式(二youwanttouseanexistingclass,anditsinterfacedoesnotmatchtheoneyouneed.youwanttocreateareusableclassthatcooperateswithunrelatedorunforeseenclasses,thatis,classesthatdon'tnecessarilyhavecompatibleinterfaces.(objectadapteronly)youneedtouseseveralexistingsubclasses,butit'simpracticaltoadapttheirinterfacebysubclassingeveryone.Anobjectadaptercanadapttheinterfaceofitsparentclass.Adapter模式Adapter模式(三Adapter模式(三–、Target、Adaptee、classadapter——objectadapter——
Adapter模式(四
Adapter模式(五class無(wú)法adaptadaptee的子類(lèi),但是可以重載adaptee的行object可以adaptadapteeHowmuchadaptingdoesAdapterPluggableUsingtwo-wayadapterstoprovide針對(duì)classadapter,用多重繼承來(lái)實(shí)
使用C++繼承機(jī)制實(shí)現(xiàn)class使用內(nèi)嵌對(duì)象技術(shù)實(shí)現(xiàn)object使 對(duì)操作,供客戶(hù)插入?——hook技術(shù)Adapter模式(Adapter模式(六RelatedC++COM中的模式8:Bridge(一Decouplean ionfromitsimplementationsothatthetwocanvaryindependently抽象(接口)與實(shí)現(xiàn)都非常。Bridge模Bridge模式(二Applicability:UsetheBridgepattern對(duì)一個(gè)實(shí)現(xiàn)的修改不影響客戶(hù)(無(wú)須重新編譯Bridge模式(三 ion,ion,Bridge模式(四二進(jìn)制兼容對(duì)客戶(hù)隱藏實(shí)現(xiàn)細(xì)
Bridge模式(五OnlyoneCreatingtherightImplementor如何創(chuàng)建?根據(jù)客戶(hù)環(huán)境,或者通過(guò)Sharing資源管理 計(jì)數(shù)技UsingmultipleRelated–Related–Factory可以用來(lái)創(chuàng)建和配置Bridge模–與Adapter–handle:文件handle、窗口插StringRep(constcharintcount;char*rep;Counted
class{String(constStringString&operator=(constStringStringRepComposite模式(Composite模式(三–,Component,Leaf,典型的composite對(duì)象結(jié)99:Composite(一Composeobjectsintotreestructurestorepresentpart-wholehierarchiesCompositelets streatindividualobjectsandcompositionsofobjectsuniformly”遞歸組Composite模式(二youwant stobeabletoignoretheindividualobjects.swilltreatallobjectsinthecompositestructureuniformly.Composite模式(Composite模式(四objectsandcompositeobjects。定義了包含leafmakesthesimple。客戶(hù)一致地處理復(fù)合對(duì)makesiteasiertoaddnewkindsofcomponentscanmakeyourdesignoverlygeneral。使得系統(tǒng)過(guò)于Composite模式(五ExplicitparentSharingizingtheComponentDeclaringthechildmanagementShouldComponentimplementalistofChildCachingtoimproveWhoshoulddeleteWhat'sthebestdatastructureforstoringComposite模Composite模式(六Related廣泛應(yīng)用于OO領(lǐng)MFC中的組件層次:ActiveX10:Facade(一Provideaunifiedinterfacetoasetofinterfacesinasubsystem.Facadedefinesahigher-levelinterfacethatmakesthesubsystemeasiertouse.Facade模式(三–Facade模式(三–facade,subsystemApplicability:UsetheFacadepattern FlyWeight模式(三FlyWeight模式(三FlyWeight模式(四Struct(續(xù)–,flyweight,concreteFlyweight,–Facade模式(四—— Facade模式(五Related–facade對(duì)象的創(chuàng)建:singleton MFCFakeMFCMapMapMapPluginMDINetscape1111:FlyWeight(一Usesharingtosupportlargenumbersoffine-grainedobjectsefficiently.當(dāng)對(duì)象的粒度太小的時(shí)候,大量對(duì)象將會(huì)產(chǎn)生巨大的資源消耗,因此考慮用共享對(duì)象(lyegh)來(lái)實(shí)現(xiàn)邏輯上的大量對(duì)象。Flght對(duì)象可用于不同的onxt中,本身固有的狀態(tài)不隨onxt發(fā)生變化,而其他的狀態(tài)隨onxt而變化FlyWeight模式(二ofthefollowingaretrue:AnapplicationusesalargenumberofStoragecostsarehighbecauseofthesheertyofMostobjectstatecanbemadeManygroupsofobjectsmayberecedbyrelativelyfewsharedobjectsonceextrinsicstateisremoved.Theapplicationdoesn'tdependonobjectidentity.Sinceflyweightobjectsmaybeshared,identitytestswillreturntrueforconceptuallydistinctobjects.FlyWeight模式(FlyWeight模式(五把對(duì)象的狀態(tài)分開(kāi):intrinsicand Removingextrinsicstate,盡可能做到實(shí)時(shí)計(jì)算(通過(guò)Managingsharedobjects,客戶(hù)不能直接實(shí)例化 Related與Composite可以用flyweight實(shí)現(xiàn)State和Strategy用flyweight實(shí)現(xiàn)celltearoff“DesignPatternsStructuralStructuralPatternsStructuralPatternsStructuralpatterns小Adapter、bridge、composite用于構(gòu)造對(duì)象組合結(jié)
BehavioralChainofResponsibilityInterpreter MediatorMementoStateTemteMethod12:12:Command(一Action,Encapsulatearequestasanobject,therebylettingyou swithdifferentrequests,queueorlogrequests,andsupportundoableoperations.Command模式(二parameterizeobjectsbyanactiontoperformspecify,queue,andexecuterequestsatdifferentsupportsupportloggingchangessothattheycanbereappliedincaseofasystemcrashstructureasystemaroundhigh-leveloperationsbuiltonprimitivesoperations——transactionsCommand模Command模式(三 Command模式(四
Command模式(五Related模式可用來(lái)實(shí) mand組為實(shí)現(xiàn)Related模式可用來(lái)實(shí) mand組為實(shí)現(xiàn)o,可以用其他行為模式來(lái)管理狀態(tài),如模式。 mnd被放到istrylst之前,可以prototype模 自Commandsarefirst-classobjectsTheycanbemanipulatedandextendedlikeanyotherobjectYoucanassemblecommandsintoacompositecommandAnexampleis It'seasytoaddnewCommands,becauseyoudon'thavetochangeexistingclassesHowinligentshouldacommandSupportingundoandAvoidingerroraccumulationintheundoUsingC++tem模式模式 tor(一ProvideawaytoaccesstheelementsofanaggregateobjectsequentiallywithoutexposingitsunderlyingAnaggregateobjectsuchasalistshouldgiveyouawaytoaccessitselementswithoutexposingitsinternalSeparatingthetraversalmechanismfromtheListobjectletsusdefinei torsfordifferenttraversalpolicieswithoutenumeratingthemintheListinterface. tor模式(二 torpatternwhenexposingitsinternalrepresentation.toprovideauniforminterfacefortraversingpolymorphici tor模式(三– tor、 tor模式(四Itsupportsvariationsinthetraversalofan torssimplifytheAggregateMorethanonetraversalcanbependingonanWhocontrolsthe externalitorversusinternaliWhodefinesthetraversal——itor定義算法——itor如何數(shù)Howrobustisthe tor模式(五Implementation(續(xù)Additional tor基本操作:First,Next,IsDone,andUsingpolymorphic tors torsmayhaveprivileged torsforcomposites——適合于internali Null
常被用 posite模式的復(fù)合結(jié)Polymorphici torsrelyonfactorymethodstoinstantiatetheappropriateICOMenumerator:connectableobject、C++在STL中,itor是連接algorithm和container14:14:Observer(一Aliases:Dependents,Publish-Defineaone-to-manydependencybetweenobjectssothatwhenoneobjectchangesstate,allitsdependentsarenotifiedandupdatedautomatically. ThekeyobjectsinthispatternaresubjectandAsubjectmayhaveanynumberofdependentAllobserversarenotifiedwheneverthesubjectundergoesachangeinstateObserver模式(二Whenan ionhastwoaspects,onedependentontheother.Encapsulatingtheseaspectsinseparateobjectsletsyouvaryandreusethemindependently.Whenachangetooneobjectrequireschangingandyoudon'tknowhowmanyobjectsneedtobeWhenanobjectshouldbeabletonotifyotherobjectswithoutmakingassumptionsaboutwhotheseobjectsare.Inotherwords,youdon'twanttheseobjectstightlyObserver模式Observer模式(三–Subject、ConcreteSubject、Observer、Observer模式(四
Observer模式(五Observer模式(六Mediator:用Mediator模Observer模式(六Mediator:用Mediator模式封裝復(fù)雜的更新語(yǔ)COMpropertyCOM+EventSupportforbroadcastUnexpected subjectstotheirObservingmorethanoneWhotriggersthe orMakingsureSubjectstateisself-consistentbeforesubject向observer傳遞變化信中間插入15:15:Strategy(一Defineafamilyofalgorithms,encapsulateeachone,andmaketheminterchangeable.Strategyletsthealgorithmvaryindependentlyfrom sthatuseit.Strategy模式(二manyrelatedclassesdifferonlyintheiryouneeddifferentvariantsofananalgorithmusesdatathat asmultipleconditionalstatementsinitsStrategy模Strategy模式(三Strategy、ConcreteStrategy、StrategyandContextincttoimplementthechosenAcontextforwardsrequestsfromitsstoitsStrategy模式(四FamiliesofrelatedAnalternativetoStrategieseliminateconditionalsmustbeawareofdifferentCommunicationoverheadbetweenStrategyandIncreasednumberofDefiningtheStrategyandContextStrategiesastemteMakingStrategyobjectsStrategy模Strategy模式(五flyweight:考慮用flyweight模式來(lái)實(shí)現(xiàn)strategy
16:Visitor(一Representanoperationtobeperformedontheelementsofanobjectstructure.Visitorletsyoudefineanewoperationwithoutchangingtheclassesoftheelementsonwhichit 不 不 piler例 TypeCheckGenerateCodePrettyPrintVariableRefNodeAssignmentNodeVisitVariableRefVisitAssignmentVisitVa
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶(hù)所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025至2030年中國(guó)汽車(chē)薄壁電線(xiàn)數(shù)據(jù)監(jiān)測(cè)研究報(bào)告
- 2025至2030年中國(guó)旋轉(zhuǎn)酒杯架數(shù)據(jù)監(jiān)測(cè)研究報(bào)告
- 2025至2030年中國(guó)交流電焊機(jī)數(shù)據(jù)監(jiān)測(cè)研究報(bào)告
- 二零二五年度汽車(chē)品牌VI設(shè)計(jì)及車(chē)主手冊(cè)合同3篇
- 二零二四年度展覽展示項(xiàng)目知識(shí)產(chǎn)權(quán)保護(hù)合同3篇
- 2025年度個(gè)人校園景觀(guān)綠化工程承包合同范本4篇
- 二零二五年度廠(chǎng)房出售附帶員工培訓(xùn)計(jì)劃合同3篇
- 二零二五年度船舶購(gòu)買(mǎi)與風(fēng)險(xiǎn)評(píng)估合同4篇
- 二零二五版跨行業(yè)合同終止與資產(chǎn)清算協(xié)議3篇
- 2025年度建筑工程項(xiàng)目管理咨詢(xún)與實(shí)施服務(wù)合同范本4篇
- 定額〔2025〕1號(hào)文-關(guān)于發(fā)布2018版電力建設(shè)工程概預(yù)算定額2024年度價(jià)格水平調(diào)整的通知
- 2024年城市軌道交通設(shè)備維保及安全檢查合同3篇
- 【教案】+同一直線(xiàn)上二力的合成(教學(xué)設(shè)計(jì))(人教版2024)八年級(jí)物理下冊(cè)
- 湖北省武漢市青山區(qū)2023-2024學(xué)年七年級(jí)上學(xué)期期末質(zhì)量檢測(cè)數(shù)學(xué)試卷(含解析)
- 單位往個(gè)人轉(zhuǎn)賬的合同(2篇)
- 電梯操作證及電梯維修人員資格(特種作業(yè))考試題及答案
- 科研倫理審查與違規(guī)處理考核試卷
- GB/T 44101-2024中國(guó)式摔跤課程學(xué)生運(yùn)動(dòng)能力測(cè)評(píng)規(guī)范
- 鍋爐本體安裝單位工程驗(yàn)收表格
- 高危妊娠的評(píng)估和護(hù)理
- 2024年山東鐵投集團(tuán)招聘筆試參考題庫(kù)含答案解析
評(píng)論
0/150
提交評(píng)論