版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領
文檔簡介
軟件設計復習提關于軟件設計復習提關于GRASP:參考筆記最后一頁;高層結(jié)部件、連接件、配高層高層抽象的作需求(質(zhì)量屬性部件、連接件、配高層高層抽象的作需求(質(zhì)量屬性、項目環(huán)境、商業(yè)關注軟件體系結(jié)交流媒介的作問題、候選設計、理由、解決方設計指導開發(fā)的作5-1理解軟件體系結(jié)構(gòu)的高層結(jié)構(gòu)Componentsarethelocusofcomputationandstate系統(tǒng)的主要狀態(tài)和計Connectorsarethelocusofrelationsamongcomponents部件間的注意:部件和連接件都是第一等級實體,占同等主要地位,連接件不直接關聯(lián)部件n決定了部件和連接件的匹配關系。Connector獨立于component:connection的定義應該本地化訪問限制可能在體系結(jié)構(gòu)=設計體系結(jié)構(gòu)+抽象體系結(jié)構(gòu)部件+連接件+配1Elementsthatencapsulateprocessinganddatainasystem’sarchitecturearereferredtoassoftwarecomponents負責系統(tǒng)的主要數(shù)據(jù)和處理的元素AsoftwarecomponentisanarchitecturalAsoftwarecomponentisanarchitecturalentityencapsulatesasubsetofthesystem’sfunctionalityand/ordatarestrictsaccesstothatsubsetviaanexplicitlydefinedinterfacehasexplicitlydefineddependenciesonitsrequiredexecutioncontext明確定義了對其執(zhí)行所需要context上下文的依賴Componentstypicallyprovideapplication-specificservicesImplementation實PrimitiveComponents原始部Modules,Compositecomponents2連接件IncomplexsystemsinteractionmaybecomechallengingthanthefunctionalityoftheindividualcomponentsAsoftwareconnectorisanarchitecturalbuildingblocktaskedeffectingandregulatinginteractionsamongcomponents負責封裝交互信息協(xié)調(diào)component間的交互的體系結(jié)構(gòu)塊,交互與componentTheymediateinteractionsbutarenot“things”tobe“hookedup;”rather,theyprovidetherulesforhooking-up. Connectorstypicallyprovideapplication-independentinteractionfacilitiesImplementation實PrimitiveCompositeCompositespecificwayina3配置Componentsandconnectorsarecomposedinsystem’sarchitecturetoaccomplishthatsystem’sobjective定系統(tǒng)體系結(jié)Anarchitecturalconfiguration,ortopology,isasetofspecificassociationsbetweenthecomponentsandconnectorsofasoftware關注點軟件體系結(jié)構(gòu)的主要關注點可以分為三個類型Rationalofsoftwarearchitecture軟件體系結(jié)構(gòu)的規(guī)則,交流媒Janusbetweenproblemdomainandsolutionsystem,ensuretheShowshowfunctionalandnon-functionalrequirementsaremet功能和Architectsareagentsofcustomsnotdevelopers體系架構(gòu)師應當代理顧客TheconceptintegrityrepresentedbysoftwarearchitecturecomeAchievingqualityattributesmustbeconsideredthroughoutdesign,implementation,anddeployment.質(zhì)量屬性必須在設計,實現(xiàn)和部署中都考慮Satisfactoryresultsdependongettingthebigpicturearchitecture&thedetails(implementationright.(bigpicutre)和實現(xiàn)availability,modifiability,performance,security,testability,andtimetomarket,cost&benefit,projectedlife,targetmarket,rolloutArchitecturalqualitiesconceptualintegritycorrectness&completenessbuildability概念 Asoftwaresystem’sarchitectureisthesetofprincipaldesigndecisionsaboutthesystem軟件體系結(jié)構(gòu)是系統(tǒng)的最基本決策的集合。Principal”impliesadegreeofimportancethatgrantsadesigndecision“architecturalstatus”“最基本”:設計決策在保證體系結(jié)構(gòu)狀態(tài)上的重要性ItimpliesthatnotalldesigndecisionsareThatis,theydonotnecessarilyimpactasystem’sReflectsmajordesigndecisions反映主要的設計決策Architectureestablishesthecontextfordesignandimplementation為Rationaleforwhyoneapproachtaken,whatimpactithas選擇的理由和anarchitecturaldesigndecisionAdescriptionofthesetofarchitecturaladditions,subtractionsandmodificationstothesoftwarearchitecture,therationale,andthedesignrules,designconstraintsandadditionalrequirementsthat(partially)realizeoneormorerequirementsonagivenarchitecture.RationaleThereasonsbehindanarchitecturaldesigndecisionItdescribeswhyachangeismadetothesoftwareDesignrulesanddesignconstraintsPrescriptionsforfurtherdesigndecisions.RulesaremandatorydescribedescribetheoppositesideofdesignrulesTheydescribewhatisnotallowedinthefutureofthedesign.非強制性規(guī)定,(什么事不能做)Additionalrequirements額外需求額外設計決bythearchitecture.Thesenewrequirementsneedtobeaddressedbyadditionaldesign補充:定義PerryandSoftwareArchitecture={Elements,Form,RationaleWhat基本單位howwhy限“Thearchitectureofasoftwaresystemdefinesthatsystemintermsofcomputationalcomponentsandinteractionsamongthosecomponents.ShawandGarlan96]軟件體系結(jié)構(gòu)定義了系統(tǒng)的計算部件和部件間的交互部件+連接件+配“Thesoftwarearchitectureofaprogramorcomputingsystemisthestructureorstructuresofthesystem,whichcomprisesoftwarecomponentstheexternallyvisiblepropertiesofthosecomponents,andtherelationshipsamongthem.”[Bass,Clements,andKazman98]軟件體系結(jié)構(gòu)是系統(tǒng)的結(jié)構(gòu),包括了軟件部件+對外可見屬性+部件間關Everysoftwarehasoneormorearchitecturestructures有軟件有一理解:參考去年整理軟件體系結(jié)構(gòu)的概高層架包括靜態(tài)和動態(tài)屬性指該系統(tǒng)的結(jié)構(gòu),包括軟件組件,及其外部可見屬性,以及組件間的關系;由計算件和組件間交互組成組件模塊,包,層,文件,數(shù)據(jù)庫,客戶端,服務如何定組件的函數(shù)和職責,以及接口必須被定連接器允許組件間交互的構(gòu)造塊(不是簡單的接口組件連接器包括顯式的和隱式的允許組件間交互的構(gòu)造塊(不是簡單的接口組件連接器包括顯式的和隱式的,有時僅僅是一個通道,有時包括自己的邏輯和常見連接器(Implicit)事件,C/S中間件,消息和消息總線,共享變量,過程調(diào)用(本地、遠程道(Explicit)代理,適配交流表現(xiàn)功能和非功能需求(質(zhì)量)如何被滿質(zhì)量的種類,,,,,商業(yè)質(zhì)量:投放市場的時間,投入&回報,計劃周期,目標市場,首次展出計劃,遺留系整建筑質(zhì)量:觀念一致性,正確性&完整性,可建造設計決策反映設計決往往根據(jù)架構(gòu)師的知識背景實建立了軟件設計和實現(xiàn)的背景,解釋一種方法被采用的根本原因,它有什么影結(jié)構(gòu)決策是最基本的決策,改變它將會引起很多連鎖的反使得修改變得容易控制,方便于系統(tǒng)原型的演軟件架構(gòu)是系統(tǒng)的基本組織,包含了它的組件,及其關系與環(huán)境,以及控制設計和演化原4+1View:多視圖模EnduserLogicalProcessPhysicalLogicalView最主要,出發(fā)點,需求的映(Object-orientedThesystemisdecomposedintoasetofkeyabstractions,taken(mostly)fromproblemdomainintheformofproblemdomainintheformofobjectsorobjectclasses系統(tǒng)被分解為關鍵抽象,從問題域{Component,connector,configuration}ViewerEnd-user終用considers:Functionalrequirements-Whatthesystemshouldprovideintermsofservicestoitsusers.功能需求,提供給用戶的服務,功能性分析,設計決策Thisdecompositionisnotonlyforthesakeoffunctionalanalysis,butalsoservestoidentifycommonmechanismsanddesignelementsacrossthevariouspartsoftheProcess(Theprocessdecomposition)viewer:Integrators集成師considers:Nonfunctionalrequirementsconcurrencyperformancescalability)styleSeveralstyleswouldfitinthisviewGarlanandShawsArchitecturestylesUsesmultiplelevelsofabstractionsalogicalnetworkofprocessesatthehighestlevel多層次抽象性,最高層是進城的邏輯網(wǎng)絡Aprocessisagroupingoftasksthatformanexecutableunit:相關tasks集結(jié)成可執(zhí)行單元,單獨進程MajorTasks:Arch.relevanttasksMinorTasks:Helpertasks.(Buffering)輔:輔助次DevelopmentBasisofalineofproductThedevelopmentarchitectureofthesystemisrepresentedbymoduleandsubsystemdiagramsshowingtheexport’andimport’relationships.系統(tǒng)分解,產(chǎn)Viewer:ProgrammersandSoftwareManagers開發(fā)人員,軟件(Hierarchyoflayers,softwaremanagement,reuse,constraintsoftools)Stylelayeredstyle分層(優(yōu)點每層可以在分解為模Physical(MappingthesoftwaretotheTopology,Thevariouselementsidentified—networks,processes,tasks,andobjects—needtobemappedontothevariousnodes.WeexpectthatseveraldifferentphysicalconfigurationswillbeusedViewer:SystemEngineers系統(tǒng)工程Considers:Non-functionalreq.regardingtounderlyinghardware(availability,(PuttingitallTheelementsinthefourviewsareshowntoworktogetherseamlesslybytheuseofasmallsetofimportantscenarios指揮,連接四個試圖:,設Helpillustrateandvalidatethedocument說明和驗證文GRASP模式GRASPstandsforGeneralResponsibilityAssignmentSoftwareGRASPpatternsfocusononeofthemostimportantaspectsofobjectdesign,assigningresponsibilitiestoclasses.LowHigh見筆記最后一頁設計模式設計結(jié)構(gòu)的抽象,針對疑難點,對原則思想的應comprisesclassand/orobject成:類和對象及其之間的關系,distillsdesignexperience設計過程中的經(jīng)驗總Designpatternshave4essentialProblem:intentcontext,whento解決方案Solution:UML-likestructure,abstract結(jié)果Consequences:resultsand模型:用于封裝與應用程序的業(yè)務邏輯相關的數(shù)據(jù)模型:用于封裝與應用程序的業(yè)務邏輯相關的數(shù)據(jù)以及對數(shù)據(jù)的處理方視圖:負責生成用戶界面的部控制器:控制器起到不同層面間的組織作用,用于控制應用程序的流1-111模塊結(jié)構(gòu)化的內(nèi)聚與耦合類型參考筆耦合一個模塊不通過正常入口轉(zhuǎn)到另一模塊內(nèi)部公共耦合:havereadandwriteaccesstothesameglobal控制耦合:ifmodule1candirectlyaffecttheexecutionofmodule2module1passesa“controlparametertomodule2withlogicalcohesion或者模2返回代碼不僅指示成功或失敗而且指示1(callingmodule)執(zhí)行一些動作。(suchaswritinganerrormessageinthecaseoffailure).據(jù)結(jié)構(gòu)或外部變量),或者無多余的信息被傳遞。舉公共耦Coincidentalcohesion:onesupportingtasksCoincidentalcohesion:onesupportingtasksthathavenomeaningfulrelationshiptooneanotherLogicalGobyCarGobyTrainGobyBoatGobyTemporalcohesion:onesupportingtasksthatareallrelatedin例如“DoAllStartupActivities,”or“DoAllShutdownProceduralcohesion:alltheoperationsitperformsarerelatedtoasequenceofstepsperformedintheprogram.CleanUtensilsfromPreviousMakePhoneChopCommunicationalcohesion:amoduleperformsoperationsrelatedtoasequenceofstepsperformedintheprogramCommunicationalcohesion:amoduleperformsoperationsrelatedtoasequenceofstepsperformedintheprogram(seeproceduralcohesion)ANDalltheactionsperformedbythemoduleareperformedonthesamedata.modulesupportingtheFindTitleofFindPriceofFindPublisherofFindAuthorofFunctionalcohesion:focusesonexactlyonegoalor“function”例如ComputeCosineofAngleInformationalcohesion:Informationalcohesiondescribesamoduleasperformingnumberofactions,eachwithauniqueentrypoint,independentcodeforeachaction,andalloperationsareperformedonthesamedata. classtype Componentcoupling:bytheuseofaclassasdomainofsomeinstancevariableofanotherclassWholevariable:Creator:Creatorinsomemethod’sHidden:GivenbyanotherScattered:在實現(xiàn)中但不在規(guī)格說明中SpecificInheritanceModificationinheritancecoupling:無規(guī)則和限制的修改2Refinementinheritancecoupling:根據(jù)規(guī)則定義新的(wholeparentandrefinementof(wholeparentandrefinementofExtensioninheritancecoupling:只增加不修改1connectionwholecontentPartofprogramhandleslookupforWhencustomernotfound,componentaddscustomerbydirectlymodifyingthecontentsofthedatastructurecontainingcustomerdata.Whencustomernotfound,componentcallstheAddCustomer()methodthatisresponsibleformaintainingcustomerdata.CommonEachsourceprocesswritesdirectlytoglobaldatastore.EachsinkprocessreadsfromglobaldataImprovementDatamanagercomponentisresponsiblefordataindatastore.Processessenddatatoandrequestdatafromdatamanager.StampTheprintroutineofthecustomerbillingacceptsacustomerdatastructureasanargument,parsesit,andprintsthename,address,andbillinginformation.ImprovementTheprintroutinetakesthecustomername,address,andbillinginformationasanLogicalAcomponentreadsinputsfromtape,disk,andnetwork.Allthecodeforthesefunctionsareinthesamecomponent.Operationsarerelated,butthefunctionsaresignificantlydifferent.Adevicecomponenthasareadoperationthatisoverriddenbysub-classcomponents.Thetapesub-classreadsfromtape.Thedisksub-classreadsfromdisk.Thenetworksub-classreadsfromthenetwork.Asysteminitializationroutine:thisroutinecontainsallofthecodeforinitializingallthepartsofthesystem.Lotsofdifferentactivitiesoccur,allatinitAsysteminitializationroutinesendsaninitializationmessagetoeachEachcomponentinitializesitselfatcomponentinstantiationEachcomponentinitializesitselfatcomponentinstantiationGeneral,Scoped模塊間connection計算:如果M個模塊共享NM*N如果M1個模塊共享N1個數(shù)據(jù),M2(M1+M2=M,N1+N2=N)個模塊共享N2個數(shù)據(jù),則有作用:Helpsdevelopersandmaintainersofthesystemfindmodulesaffectedbya幫助開發(fā)者和維護者找到被變化影響的模塊.Well-structuredModuleGuideneededtoprovidedevelopmentsupportandtocutdownmaintenancecosts.結(jié)構(gòu)良好的moduleguide可以提供開發(fā)支持和減少維護開銷Specifically,foreachmoduletheModuleGuidestatesthesecretsassociatedwitheachmodulePrimarySecret:hiddeninformationthatwasspecifiedtothesoftwaredesignerHiddeninformationcontainedwithinPrimarySecret:hiddeninformationthatwasspecifiedtothesoftwaredesignerHiddeninformationcontainedwithinthemodule.準備對外隱藏andasecondarysecretwhichreferstoimplementationdecisionsmadebythedesignerwhenimplementingthemoduledesignedtohidetheprimarysecret.Implementationdecisionsusedtoimplementthetherolesplayedbytheindividualmodulesintheoverallsystemoperation;模塊thefacilitiesprovidedbyeachmodule.ModuleGuideHelpsdevelopersandmaintainersofthesystemfindmodulesaffectedbyachange幫助開發(fā)者,維護者找到被改變影響的模塊ModuleInterfaceDocumentContainspreciseandcompletedescriptionofinterfacetoeachmodule精確完整的描述每個模塊的接口ModuleDesignDocumentAninternaldesigndocumentforeachimplementationofamodule每個模塊實現(xiàn)的內(nèi)部設計文檔RequirementsDocumentModuleGuidereferstoitfortherelatedchanges(不考察給代碼的情況,以下內(nèi)容參考去年總結(jié)材料1以模塊為對象的體系結(jié)構(gòu)風InteractionShareData(BlackBoard,InteractionDataFlow(BatchSequential,PipeandFilter)ControlExplicit(CallandMainprogramandChangeinInteractionShareData(BlackBoard,InteractionDataFlow(BatchSequential,PipeandFilter)ControlExplicit(CallandMainprogramandChangeinChanginSpaceTimeReuseMainProgramandSubroutineComponents:Connectors:MainProgramandSubroutineComponents:Connectors:順序系Object-OrientedComponents:Connectors:PipeandFilterArchitecturalPipeandFilterArchitecturalConnectors:Pipe,作為流傳輸?shù)耐ǖ溃岩粋€Filter的輸出傳到另一個的輸入整個網(wǎng)絡的正確性不應該依賴于Filter的排列順序完全獨立,可以隨時增減filter,可以并行開發(fā)Implicitinvocation(Eventbased)Componentsagent代理程序(對Connectors:broadcastConnectors:每個agent的行為方式:(LayeredComponents:Connectors:LayeredComponents:Connectors:MVCModel:維護領域模型,并通知View相關變化Controller:改變model 2以進程為對象的體系2以進程為對象的體系結(jié)構(gòu)風格Publish-SubscribeArchitectureConnector:event 以物理單元 以物理單元為對象的體系結(jié)構(gòu)風Client-Three-Tier(N-Tier)DistributedObjectsDistributedResources(http)Client-Components:Connectors:RPC的交互協(xié)議(缺點:server設計困難,成為瓶頸層:存儲層(或者后端):Peer-to-::舉例:eMuleeDonkey,Gnutella,Freenet,OnShareetc.areexamplesofaP2PDistributedMida(http全局分全局分Globalmovingfromsoftwarerequirementsspecificationtostructuralviewsofthesoftwarearchitecture從軟件需求規(guī)格到軟件體系結(jié)構(gòu)的結(jié)構(gòu)化視圖的過程步驟:Globalanalysisactivitiesandoneistodesignanddescribethestructureofthesystem.設計和描述系統(tǒng)的結(jié)Usefourcomplementaryviewstoreducethecomplexityofdesigningandunderstandingthearchitecture.利用互補的視圖來減少設計和理解體Differentviewshavedifferentengineeringconcerns,sonotallaspectsofthesystemmustbeconsideredatonce.不同視圖有不同關注點,并不ThesecondpartofourapproachisGlobalGlobalAnalysisproducesdocumentationartifactsthatdescribethecontextandrationalefordesigndecisionsGA生描述設計決策上下文和Identifytheexternalinfluencingfactorsandcriticalrequirementsthatcouldaffectthearchitecture標識可能影響體系結(jié)構(gòu)的外部影響因素和關鍵Analyzethemtocomeupwithstrategiesfordesigningthearchitecture2aAnalyzingfactors(constraintsandquality)Three(3)stepStep1:Identifyanddescribethefactors識別可能影響系統(tǒng)體系結(jié)構(gòu)的需Productfactors:Systemqualityattribute產(chǎn)品因素:質(zhì)量需Organizationalfactors:Businessqualityattribute織因素:業(yè)務Step2:Describingfactors,CharacterizetheStep2:Describingfactors,CharacterizetheflexibilityorchangeabilityofthefactorsStep3:AnalyzetheimpactofthefactorsfactorThree3stepsprocedure產(chǎn)生issueRelatingfactorstoproblems目的:彌補規(guī)格需求和SA軟件體系結(jié)構(gòu)件的gap差距;重點關注體系結(jié)構(gòu)設計需求(ADR:architecturedesignrequirements)GA:將ADR(SSS:system據(jù)SSS和集中式委派式分散式AcontrolstyleisawaythatdecisionmakingisdistributedamongprogramCentralized—AfewcontrollermakeallsignificantDelegated—DecisionmakingisdistributedthroughtheprogramwithafewcontrollersmakingthemaindecisionsDispersed—Decisionmakingisspreadwidelythroughtheprogramwithfewornocomponentsmakingdecisionsontheirown Collection和實例Ceae)neIt//clientCeae)neIt//client())Aggreea)emyList=egate(m(=terator(Proxypattern:clientsubject接口交問題:提供代理以供其他對object的訪問。遠程:提供給不同的地址空間的地址的對象的本地代理虛擬:根據(jù)需求創(chuàng)建開銷對象Subject,realsubjectand用戶subject中定義的抽象方法進行操subject的實現(xiàn)在realsubject和proxy中如果接受到有危險的調(diào)用,exception或者alarm提Proxy代理了對于realsubject安全調(diào)用。Clientproxy.Proxy模式引入了對于對象的一個間接的訪問方式遠程proxy隱藏了遠程的實現(xiàn)事實object不在同一地oIteratorfirst(虛擬proxy可以進行優(yōu)化,實際對象仍存在保護proxy額外的安全。簡單,控制,安虛擬proxy可以進行優(yōu)化,實際對象仍存在保護proxy額外的安全。簡單,控制,安全,允許寫但是需要迭代器實現(xiàn))refers pattern:原型類聲明一個用來克隆自己的接傳遞拷貝,用原型實例表示要創(chuàng)建的對象類型,通過拷貝為原型創(chuàng)建新的對象思想:請求后得到拷貝,新的object,每個請求得到拷貝的不同版本參與者Prototype原型:生命了拷貝自己的接concretePrototype具體原型:clone自己的實現(xiàn)操客戶:對原型請求的對象,通過請求原型對象克隆自己來創(chuàng)建新對總結(jié):針對接口編程,而不是實現(xiàn)繼承允許定義一組有相同接口的對所有引申類都與基礎類有共享的接所有子類回應在其抽象父類接口中的請求LSP:所有類都必須可以被其父類替換,子類可以替代父類存在De-Coupling有哪些手LSP:所有類都必須可以被其父類替換,子類可以替代父類存在De-Coupling有哪些手段Avoidrepetition:doitonce防止避免重重復意味著耦合,因為對重復代碼的一塊進行改變意味著要改抽象依賴倒置,依賴接口而不是依賴實抽象不能依賴細節(jié),細節(jié)應該依賴抽高層模塊不應該依賴于底層模塊,二者都應依賴于抽在一個分離模塊即將實現(xiàn)的模塊中定義接口,基本的方式來打破依賴和降ehanisdependsMediatorpattern調(diào)停者模式通過避免對象互相顯式的指向?qū)Ψ綇亩档婉顔栴}多個對象重復訪問,無規(guī)律性一個對象集合的交互良好定義,但是交互方式復雜。通常有非結(jié)構(gòu)依賴對象復用困難,因為對象指向和交互很多其他的對Mediator:定義了與colleague對象交互的接口,通常被告知事件或者狀concreteMediator:實現(xiàn)與colleague交互的具體行為,了解和維護colleaguecolleague道自己Mediator每colleague與其他colleague互時需要先與自己的mediator互,為mediator供了服務,colleague可能請求相同也可能不同結(jié)果定義對象,其封裝了一組對象的交互方 促進低耦合,通過紡織對象顯示的引用彼此讓人獨立的拓展其交集中式控 icyMechanisdependMhan.Bridgepattern橋接模式:問題常Bridgepattern橋接模式:問題常用的處理一個抽象有多種實現(xiàn)的方式是繼然而這會使實現(xiàn)與抽象進行綁并不能夠靈活,可能需要獨立的修改實現(xiàn)或參與者Abstraction:定義了抽象RefinedAbstraction:拓展由abstraction定義的接Implementorabstraction了原始操作,abstration提供更加高級的基于該原始操作的操作。實現(xiàn)和接口之間解耦合,抽象與實現(xiàn)獨立避免了類型檢查,降低了變異的時間,減少了編譯時的依賴提高了系統(tǒng)的可擴展將實現(xiàn)細節(jié)隱藏,用戶不可內(nèi)聚又是可以實現(xiàn)差異性,接口實現(xiàn)都可以修改,抽象和實一個模塊的信息隱藏有哪兩種基本類型1)每個模塊有一個基本外部的行為和內(nèi)部隱每個模塊隱藏重要的設計決策的實現(xiàn),只有模塊的組成可以了解細方法:門面模式FacadepatternOCP:模塊可能有附加secrets:secretOCP:Open/closedprinciple開關原則?軟件實體應該對擴展開放,對修改OCP:Open/closedprinciple開關原則?軟件實體應該對擴展開放,對修改關閉。change方法:策略模式StrategypatternDecoratorpattern適配器模式AdaptorBasicFa?adeAnticipateStrategy如果上下文也有可變性:用橋接模式Beopenforextension,Beclosedfor問題 在不修改類代碼的情況Beopenforextension,Beclosedfor問題 在不修改類代碼的情況下拓展類的實例的功用聚合代替繼承,比靜態(tài)的繼承更加靈關鍵是對其裝飾的組件來說,decorator是透明的,這樣可以嵌套定義結(jié)比繼承更加靈防止繼承樹堆積過高而過于復有很多類很相似,理解上比較困難,難以理解和調(diào)及其組件并不相同,檢查對象相似性和相同性可能引起問Adapter思想新增加功能使用已有接口時,接口不將類的接口轉(zhuǎn)化為用戶期待讓類共同工作,不受到不兼容接口的影解決結(jié)果靈活性:框架可被開發(fā)用來與不兼容的類協(xié)重用性:現(xiàn)有類實現(xiàn)的有用功能可以被重類之間的接口協(xié)健壯性:現(xiàn)有類被重用但是不需要修改,防止引入不必要的潛在實現(xiàn)共性與可變性有哪些手段12StrategypatternPNightTrafficeRushDayTiCyc實現(xiàn)共性與可變性有哪些手段12StrategypatternPNightTrafficeRushDayTiCycCyclCycle()LightsPolicy*IntersectNextEvent()ChangePolicy(LightsPTrafficStrategy問題許多相關的類只是在其行為表現(xiàn)上不同,strategy提供一種給類配置多種行為的一種Strategy問題許多相關的類只是在其行為表現(xiàn)上不同,strategy提供一種給類配置多種行為的一種一個雷定義許多行為,這些在其操作中作為多種狀態(tài)條件存需要算法差異性可變性與重用性一組相關的算法擴子類的替代:context類分配為子類,直接給其其差異性復雜性,難于理好:strategy減少了條件判斷語壞:邏輯分離,用戶必須意識到是不同的strategy如果復雜和多種算如果在某些固定特點中有變更的行如果有復雜的條件判定語問題對象的行為依賴于其狀態(tài):運行時的變更行為依賴于狀解決求concretestateDUIXIANG狀態(tài)決定concreteState類,把自己作為參數(shù)傳遞給Context只提供interface,物具體內(nèi)容,用戶不直接與state切換狀態(tài):context或者concretecontext對象可以決定concreteState對象的變結(jié)果根據(jù)狀態(tài)表根據(jù)狀態(tài)表現(xiàn)異常性,狀態(tài)轉(zhuǎn)換,本地狀態(tài)決定特定行為容易增加新的狀態(tài):新的concrete增加了類結(jié)構(gòu)的規(guī)可以共享數(shù)據(jù)區(qū):如果無實舉例:publicinterfaceIState{}PublicclassOffStateIState{PublicvoidswitchFire(FireSwitchsw){sw.setState(newSmallState());}}…3運行時靜態(tài)編譯:共運行時注冊:差異Callbacks:用戶方法,注冊在服務器,服務器可以撤銷。用于拓展的方式。在服務器的對象上操Observerpattern:1問題定義了對象間的一對多的依賴,這樣一個對象改變狀態(tài),其依賴被通知并自解決結(jié)果靈活性,可變性和重用性:“event”事件風格,低耦更加復雜:難于理解和測使用:調(diào)用對方時又差異性問題,不知對方狀當一個對象改變需要改變其他,但不知道要改變的是哪個對當對象應該通知其他其他對象,但不假設其知道哪些對象。不希望這些對象緊密耦 Command問題專 Command問題專門對對象進行注冊,action處理后交給別人管通過對象的行為來參數(shù)化對可以在任何時刻制定,queue隊列和執(zhí)行通過存儲context上下文來支持結(jié)果解耦合了請receiver和可以在?;蛘哧犃兄写鎯γ睿好钐幚砥髂J骄S護歷史記容易支持undoredo:必須提供多余的狀態(tài)信息來防止易于拓展指對象的創(chuàng)建有哪些常見解決方法簡單 無限制的實例,創(chuàng)建一個類型,簡單實例化和初始CreatorpatternCouplingpatternCohesion復雜Singletonpattern問題:又是需要一個特定類只有一個實解決Constructorprivate:無法從外部調(diào)生命類的實例的私有靜態(tài)單解決Constructorprivate:無法從外部調(diào)生命類的實例的私有靜態(tài)單寫公共的方法或者相似方法,允許對單個實例進行訪保護或者綜合方法來保證其在多線程程序上可以運)例publicclassSingletonprivatestaticSingletoninstance=privateSingleton()//}publicstaticSingleton{if(instance==null)instance=new}return}//..其它實}2(思考題中有)場景3:多種類型,創(chuàng)建類型的差異性SimpleSimplefactory實例…ct把創(chuàng)建不同pizza的If-else把創(chuàng)建不同pizza的If-elseProduct:定義factorymethod:實現(xiàn)了Creator:聲明了factorymethod,返回product類型的對象;也可能定義了factorymentod的缺省實現(xiàn),返回缺省的concreteproduct類ConcreteCreator:重寫factorymehtod,返回一個concreteproduct的實例Client需要產(chǎn)生creatorconcreteProduct對象Factorymethod的例Abstractfactory:指一個工廠等級結(jié)構(gòu)可以創(chuàng)建出分屬于不同產(chǎn)品等級結(jié)構(gòu)的一個產(chǎn)品目的Factorymethod的例Abstractfactory:指一個工廠等級結(jié)構(gòu)可以創(chuàng)建出分屬于不同產(chǎn)品等級結(jié)構(gòu)的一個產(chǎn)品目的:為創(chuàng)建一組相關或者依賴的類型提供接口,但無需知道其具體類解決abstractFactory:聲明了一個實例,該實例的主要操作是產(chǎn)生singleton初始化,唯一性Abatractproduct:聲明了一個product對象的類型的接口,concretefactory產(chǎn)生concreteproductsConcreteproduct:定義了要由對應的concretefactory來創(chuàng)建product對象結(jié)果好abstract使交換產(chǎn)品家族容易:只要改變加強products之間的一壞很難支持新類型的產(chǎn)需要重abstractfactory和其子Abstractfactory和Abstractfactory和Prototypepatternp=cloreturncopytfcopyp=cloreturncopytfcopyof 設計模式部分所有的思考尋找一個需要訪問集合變量的簡單場景:編程實現(xiàn):IteratorPatternandProxy//學生打印出所有的答interface{void}//集合interfacepublicIterator}//代理模式中的realsubjectIStudent{Answersans;publicvoid{String[]str={"a","b","c"};ans=newAnswers(str);}publicvoid}}IStudent{Studentst;publicvoidprintAnswer(){}t}//答案的枚舉Iterator{Answersans;int}//答案的枚舉Iterator{Answersan
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 二零二四年醫(yī)療電子設備臨床試驗服務合同3篇
- 2025年新能源項目掛靠聘用合同規(guī)范文本
- 二手房購買權益合同2024版版B版
- 2025年度鍋爐房安全運行風險評估與管理承包合同
- 2025年度股東權益細化與公司治理創(chuàng)新合同
- 2025年度兒童插畫畫冊制作合同
- 2025年度綠色建筑設計與施工合同交底指南
- 2025年度國際貿(mào)易實務第4章國際貨物運輸與貨物包裝材料供應合同(材料供應)
- 2025年度汽車經(jīng)銷商融資擔保合同全文展示
- 2025年度房產(chǎn)租賃保證金合同
- 第1課 隋朝統(tǒng)一與滅亡 課件(26張)2024-2025學年部編版七年級歷史下冊
- 【歷史】唐朝建立與“貞觀之治”課件-2024-2025學年統(tǒng)編版七年級歷史下冊
- 產(chǎn)業(yè)園區(qū)招商合作協(xié)議書
- 2024年廣東省公務員錄用考試《行測》真題及答案解析
- 盾構(gòu)標準化施工手冊
- 天然氣脫硫完整版本
- 人教版八級物理下冊知識點結(jié)
- 2021年高考真題-生物(湖南卷) 含解析
- 新疆2024年新疆和田師范??茖W校招聘70人筆試歷年典型考題及考點附答案解析
- 【正版授權】 ISO 15978:2002 EN Open end blind rivets with break pull mandrel and countersunk head - AIA/St
- 2024山西文旅投資集團招聘117人公開引進高層次人才和急需緊缺人才筆試參考題庫(共500題)答案詳解版
評論
0/150
提交評論