




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
軟件設(shè)計模式(二軟件設(shè)計模式(二內(nèi)復(fù)習(xí)復(fù)習(xí):patternDesignpatternsrepresentsolutionstoproblemsthatarisewhendevelo softwarewithinaparticularcontext關(guān)于patternpatternpattern復(fù)習(xí):如何描述一個模Designpatternname,AliasesorAlsoKnownProblem,IntentorContext,RelatedExamples,Known復(fù)習(xí):creationalFactory本質(zhì):用一個virtualmethod完成創(chuàng)建過
Structural一個product族的factorymethod構(gòu)成了一個factory通過product原型來構(gòu)造product,Clone+prototype通過一個構(gòu)造算法和builder接口把構(gòu)造過程與客 單實例類型,如何構(gòu)造這單個實例?如 這單個實例把對象的獲取過程與客
**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,用多重繼承來實
使用C++繼承機制實現(xiàn)class使用內(nèi)嵌對象技術(shù)實現(xiàn)object使 對操作,供客戶插入?——hook技術(shù)Adapter模式(Adapter模式(六RelatedC++COM中的模式8:Bridge(一Decouplean ionfromitsimplementationsothatthetwocanvaryindependently抽象(接口)與實現(xiàn)都非常。Bridge模Bridge模式(二Applicability:UsetheBridgepattern對一個實現(xiàn)的修改不影響客戶(無須重新編譯Bridge模式(三 ion,ion,Bridge模式(四二進制兼容對客戶隱藏實現(xiàn)細
Bridge模式(五OnlyoneCreatingtherightImplementor如何創(chuàng)建?根據(jù)客戶環(huán)境,或者通過Sharing資源管理 計數(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)對象的粒度太小的時候,大量對象將會產(chǎn)生巨大的資源消耗,因此考慮用共享對象(lyegh)來實現(xiàn)邏輯上的大量對象。Flght對象可用于不同的onxt中,本身固有的狀態(tài)不隨onxt發(fā)生變化,而其他的狀態(tài)隨onxt而變化FlyWeight模式(二ofthefollowingaretrue:AnapplicationusesalargenumberofStoragecostsarehighbecauseofthesheertyofMostobjectstatecanbemadeManygroupsofobjectsmayberecedbyrelativelyfewsharedobjectsonceextrinsicstateisremoved.Theapplicationdoesn'tdependonobjectidentity.Sinceflyweightobjectsmaybeshared,identitytestswillreturntrueforconceptuallydistinctobjects.FlyWeight模式(FlyWeight模式(五把對象的狀態(tài)分開:intrinsicand Removingextrinsicstate,盡可能做到實時計算(通過Managingsharedobjects,客戶不能直接實例化 Related與Composite可以用flyweight實現(xiàn)State和Strategy用flyweight實現(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模式可用來實 mand組為實現(xiàn)Related模式可用來實 mand組為實現(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模式來實現(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)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 二年級數(shù)學(xué)下冊教案-7 角的初步認識(46)-蘇教版
- Unit 5 Section B 3a - selfcheck 教學(xué)設(shè)計 2024-2025學(xué)年人教版八年級英語下冊
- 3-復(fù)式統(tǒng)計表-人教版三年級數(shù)學(xué)下冊單元測試卷(含答案)
- 2024年折射儀項目資金籌措計劃書代可行性研究報告
- 2025年安全員C證(專職安全員)考試題庫
- 2024年包裝檢測儀器項目投資申請報告代可行性研究報告
- 2025年甘肅衛(wèi)生職業(yè)學(xué)院單招職業(yè)適應(yīng)性測試題庫匯編
- 2025年度教育行業(yè)資金監(jiān)管賬戶委托管理合同
- 2025年度城市綠地經(jīng)營權(quán)轉(zhuǎn)讓及生態(tài)維護合同
- 2025年度員工住宿安全與設(shè)施改造協(xié)議
- 淺談鋼琴即興伴奏在教學(xué)中應(yīng)用現(xiàn)狀及提高方法 論文
- 2024屆高考語文復(fù)習(xí):小說閱讀之?dāng)⑹马樞蚺c敘事節(jié)奏
- 太陽能光電轉(zhuǎn)換西安交通大學(xué)PP課件
- 新生兒肺透明膜病的影像與臨床探討
- 動力觸探檢測報告超重型圓錐動力觸探試驗
- 職業(yè)素養(yǎng)的內(nèi)容(含事例)課件
- 工藝美術(shù)專業(yè)-工藝品設(shè)計課程標準
- 環(huán)衛(wèi)市場化運營方案PPT
- 二年級下冊綜合實踐活動說課稿-我是清潔小衛(wèi)士 全國通用
- 教師師德考核表
- 人教版(2023)必修三 Unit 3 Diverse Cultures 單元整體教學(xué)設(shè)計(表格式)
評論
0/150
提交評論