




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(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)建過
Structural一個(gè)product族的factorymethod構(gòu)成了一個(gè)factory通過product原型來構(gòu)造product,Clone+prototype通過一個(gè)構(gòu)造算法和builder接口把構(gòu)造過程與客 單實(shí)例類型,如何構(gòu)造這單個(gè)實(shí)例?如 這單個(gè)實(shí)例把對(duì)象的獲取過程與客
**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無法adaptadaptee的子類,但是可以重載adaptee的行object可以adaptadapteeHowmuchadaptingdoesAdapterPluggableUsingtwo-wayadapterstoprovide針對(duì)classadapter,用多重繼承來實(shí)
使用C++繼承機(jī)制實(shí)現(xiàn)class使用內(nèi)嵌對(duì)象技術(shù)實(shí)現(xiàn)object使 對(duì)操作,供客戶插入?——hook技術(shù)Adapter模式(Adapter模式(六RelatedC++COM中的模式8:Bridge(一Decouplean ionfromitsimplementationsothatthetwocanvaryindependently抽象(接口)與實(shí)現(xiàn)都非常。Bridge模Bridge模式(二Applicability:UsetheBridgepattern對(duì)一個(gè)實(shí)現(xiàn)的修改不影響客戶(無須重新編譯Bridge模式(三 ion,ion,Bridge模式(四二進(jìn)制兼容對(duì)客戶隱藏實(shí)現(xiàn)細(xì)
Bridge模式(五OnlyoneCreatingtherightImplementor如何創(chuàng)建?根據(jù)客戶環(huán)境,或者通過Sharing資源管理 計(jì)數(shù)技UsingmultipleRelated–Related–Factory可以用來創(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。客戶一致地處理復(fù)合對(duì)makesiteasiertoaddnewkindsofcomponentscanmakeyourdesignoverlygeneral。使得系統(tǒng)過于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)來實(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)分開:intrinsicand Removingextrinsicstate,盡可能做到實(shí)時(shí)計(jì)算(通過Managingsharedobjects,客戶不能直接實(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模式可用來實(shí) mand組為實(shí)現(xiàn)Related模式可用來實(shí) mand組為實(shí)現(xiàn)o,可以用其他行為模式來管理狀態(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ù)雜的更新語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模式來實(shí)現(xiàn)strategy
16:Visitor(一Representanoperationtobeperformedontheelementsofanobjectstructure.Visitorletsyoudefineanewoperationwithoutchangingtheclassesoftheelementsonwhichit 不 不 piler例 TypeCheckGenerateCodePrettyPrintVariableRefNodeAssignmentNodeVisitVariableRefVisitAssignmentVisitVa
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2024廣西南寧市軍糧供應(yīng)有限公司招聘3人筆試參考題庫附帶答案詳解
- 2024中煤集團(tuán)山西有限公司面向社會(huì)公開招聘292人筆試參考題庫附帶答案詳解
- 2024年泉州市采購集團(tuán)有限責(zé)任公司招聘勞務(wù)派遣人員1人筆試參考題庫附帶答案詳解
- 2025年會(huì)計(jì)職稱考試《初級(jí)會(huì)計(jì)實(shí)務(wù)》財(cái)務(wù)風(fēng)險(xiǎn)預(yù)警綜合測(cè)試試題卷
- 2025年征信法規(guī)解讀與征信業(yè)務(wù)監(jiān)管政策試題
- 2025年專升本藝術(shù)概論模擬試卷:探討藝術(shù)與科技融合創(chuàng)新實(shí)踐
- 2025年小學(xué)語文畢業(yè)升學(xué)考試全真模擬卷(閱讀寫作強(qiáng)化版)-作文構(gòu)思與表達(dá)技巧訓(xùn)練
- 2025年教師資格證面試結(jié)構(gòu)化模擬題:幼兒園美術(shù)教學(xué)活動(dòng)設(shè)計(jì)試題
- 2025年電工中級(jí)職業(yè)技能考試真題卷(電氣設(shè)備運(yùn)行與維護(hù)技術(shù))
- 2025年統(tǒng)計(jì)學(xué)期末考試題庫:統(tǒng)計(jì)推斷與檢驗(yàn)在旅游管理研究中的試題
- 2024中國慢性阻塞性肺疾病基層診療與管理指南解讀
- 重難點(diǎn)31 阿基米德三角形(舉一反三)(新高考專用)(學(xué)生版) 2025年高考數(shù)學(xué)一輪復(fù)習(xí)專練(新高考專用)
- 青春自護(hù)-遠(yuǎn)離不良誘惑主題班會(huì)
- 生豬屠宰獸醫(yī)衛(wèi)生檢驗(yàn)人員理論考試題庫及答案
- 《大自然的語言》課件
- 智能安防監(jiān)控系統(tǒng)維護(hù)手冊(cè)
- 人教版 八年級(jí)上冊(cè)音樂 第三單元 洪湖水浪打浪 教案
- 理解性默寫 2023-2024學(xué)年統(tǒng)編版高中語文必修下冊(cè)
- 照明燈具安裝施工工藝方案
- 征管5c質(zhì)量評(píng)價(jià)培訓(xùn)
- 腫瘤療效評(píng)估新標(biāo)準(zhǔn)mRECIST標(biāo)準(zhǔn)
評(píng)論
0/150
提交評(píng)論