windows編程潘愛(ài)民com講座續(xù)介紹一些重要的模式_第1頁(yè)
windows編程潘愛(ài)民com講座續(xù)介紹一些重要的模式_第2頁(yè)
windows編程潘愛(ài)民com講座續(xù)介紹一些重要的模式_第3頁(yè)
windows編程潘愛(ài)民com講座續(xù)介紹一些重要的模式_第4頁(yè)
windows編程潘愛(ài)民com講座續(xù)介紹一些重要的模式_第5頁(yè)
已閱讀5頁(yè),還剩8頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(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ì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論