版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
軟件設(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í)例把對象的獲取過程與客
**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針對classadapter,用多重繼承來實(shí)
使用C++繼承機(jī)制實(shí)現(xiàn)class使用內(nèi)嵌對象技術(shù)實(shí)現(xiàn)object使 對操作,供客戶插入?——hook技術(shù)Adapter模式(Adapter模式(六RelatedC++COM中的模式8:Bridge(一Decouplean ionfromitsimplementationsothatthetwocanvaryindependently抽象(接口)與實(shí)現(xiàn)都非常。Bridge模Bridge模式(二Applicability:UsetheBridgepattern對一個(gè)實(shí)現(xiàn)的修改不影響客戶(無須重新編譯Bridge模式(三 ion,ion,Bridge模式(四二進(jìn)制兼容對客戶隱藏實(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對象結(jié)99:Composite(一Composeobjectsintotreestructurestorepresentpart-wholehierarchiesCompositelets streatindividualobjectsandcompositionsofobjectsuniformly”遞歸組Composite模式(二youwant stobeabletoignoretheindividualobjects.swilltreatallobjectsinthecompositestructureuniformly.Composite模式(Composite模式(四objectsandcompositeobjects。定義了包含leafmakesthesimple??蛻粢恢碌靥幚韽?fù)合對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對象的創(chuàng)建:singleton MFCFakeMFCMapMapMapPluginMDINetscape1111:FlyWeight(一Usesharingtosupportlargenumbersoffine-grainedobjectsefficiently.當(dāng)對象的粒度太小的時(shí)候,大量對象將會產(chǎn)生巨大的資源消耗,因此考慮用共享對象(lyegh)來實(shí)現(xiàn)邏輯上的大量對象。Flght對象可用于不同的onxt中,本身固有的狀態(tài)不隨onxt發(fā)生變化,而其他的狀態(tài)隨onxt而變化FlyWeight模式(二ofthefollowingaretrue:AnapplicationusesalargenumberofStoragecostsarehighbecauseofthesheertyofMostobjectstatecanbemadeManygroupsofobjectsmayberecedbyrelativelyfewsharedobjectsonceextrinsicstateisremoved.Theapplicationdoesn'tdependonobjectidentity.Sinceflyweightobjectsmaybeshared,identitytestswillreturntrueforconceptuallydistinctobjects.FlyWeight模式(FlyWeight模式(五把對象的狀態(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)造對象組合結(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等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年度汽車租賃與智能交通系統(tǒng)對接合同3篇
- 2025-2030全球全自動農(nóng)業(yè)機(jī)器人行業(yè)調(diào)研及趨勢分析報(bào)告
- 2024年全國數(shù)控技能大賽理論考試題庫-上(單選題) (二)
- 2025年度鋼管架施工設(shè)備租賃合同樣本
- 2025年度個(gè)人反擔(dān)保合同糾紛解決協(xié)議
- 2025年度數(shù)字電視信號接收器采購合同4篇
- 2025版施工合同擔(dān)保人資質(zhì)審核及責(zé)任規(guī)范3篇
- 教育者與科技聯(lián)手強(qiáng)化校園安全措施
- 2025年度商鋪物業(yè)管理與商業(yè)策略規(guī)劃合同4篇
- 二零二五年度茶館社區(qū)服務(wù)合作協(xié)議4篇
- 定額〔2025〕1號文-關(guān)于發(fā)布2018版電力建設(shè)工程概預(yù)算定額2024年度價(jià)格水平調(diào)整的通知
- 2024年城市軌道交通設(shè)備維保及安全檢查合同3篇
- 電力溝施工組織設(shè)計(jì)-電纜溝
- 單位往個(gè)人轉(zhuǎn)賬的合同(2篇)
- 科研倫理審查與違規(guī)處理考核試卷
- GB/T 44101-2024中國式摔跤課程學(xué)生運(yùn)動能力測評規(guī)范
- 鍋爐本體安裝單位工程驗(yàn)收表格
- 一種基于STM32的智能門鎖系統(tǒng)的設(shè)計(jì)-畢業(yè)論文
- 高危妊娠的評估和護(hù)理
- 妊娠合并強(qiáng)直性脊柱炎的護(hù)理查房
- 2024年山東鐵投集團(tuán)招聘筆試參考題庫含答案解析
評論
0/150
提交評論