版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
軟件設(shè)計(jì)復(fù)習(xí)提關(guān)于軟件設(shè)計(jì)復(fù)習(xí)提關(guān)于GRASP:參考筆記最后一頁(yè);高層結(jié)部件、連接件、配高層高層抽象的作需求(質(zhì)量屬性部件、連接件、配高層高層抽象的作需求(質(zhì)量屬性、項(xiàng)目環(huán)境、商業(yè)關(guān)注軟件體系結(jié)交流媒介的作問(wèn)題、候選設(shè)計(jì)、理由、解決方設(shè)計(jì)指導(dǎo)開(kāi)發(fā)的作5-1理解軟件體系結(jié)構(gòu)的高層結(jié)構(gòu)Componentsarethelocusofcomputationandstate系統(tǒng)的主要狀態(tài)和計(jì)Connectorsarethelocusofrelationsamongcomponents部件間的注意:部件和連接件都是第一等級(jí)實(shí)體,占同等主要地位,連接件不直接關(guān)聯(lián)部件n決定了部件和連接件的匹配關(guān)系。Connector獨(dú)立于component:connection的定義應(yīng)該本地化訪問(wèn)限制可能在體系結(jié)構(gòu)=設(shè)計(jì)體系結(jié)構(gòu)+抽象體系結(jié)構(gòu)部件+連接件+配1Elementsthatencapsulateprocessinganddatainasystem’sarchitecturearereferredtoassoftwarecomponents負(fù)責(zé)系統(tǒng)的主要數(shù)據(jù)和處理的元素AsoftwarecomponentisanarchitecturalAsoftwarecomponentisanarchitecturalentityencapsulatesasubsetofthesystem’sfunctionalityand/ordatarestrictsaccesstothatsubsetviaanexplicitlydefinedinterfacehasexplicitlydefineddependenciesonitsrequiredexecutioncontext明確定義了對(duì)其執(zhí)行所需要context上下文的依賴Componentstypicallyprovideapplication-specificservicesImplementation實(shí)PrimitiveComponents原始部Modules,Compositecomponents2連接件IncomplexsystemsinteractionmaybecomechallengingthanthefunctionalityoftheindividualcomponentsAsoftwareconnectorisanarchitecturalbuildingblocktaskedeffectingandregulatinginteractionsamongcomponents負(fù)責(zé)封裝交互信息協(xié)調(diào)component間的交互的體系結(jié)構(gòu)塊,交互與componentTheymediateinteractionsbutarenot“things”tobe“hookedup;”rather,theyprovidetherulesforhooking-up. Connectorstypicallyprovideapplication-independentinteractionfacilitiesImplementation實(shí)PrimitiveCompositeCompositespecificwayina3配置Componentsandconnectorsarecomposedinsystem’sarchitecturetoaccomplishthatsystem’sobjective定系統(tǒng)體系結(jié)Anarchitecturalconfiguration,ortopology,isasetofspecificassociationsbetweenthecomponentsandconnectorsofasoftware關(guān)注點(diǎn)軟件體系結(jié)構(gòu)的主要關(guān)注點(diǎn)可以分為三個(gè)類型Rationalofsoftwarearchitecture軟件體系結(jié)構(gòu)的規(guī)則,交流媒Janusbetweenproblemdomainandsolutionsystem,ensuretheShowshowfunctionalandnon-functionalrequirementsaremet功能和Architectsareagentsofcustomsnotdevelopers體系架構(gòu)師應(yīng)當(dāng)代理顧客TheconceptintegrityrepresentedbysoftwarearchitecturecomeAchievingqualityattributesmustbeconsideredthroughoutdesign,implementation,anddeployment.質(zhì)量屬性必須在設(shè)計(jì),實(shí)現(xiàn)和部署中都考慮Satisfactoryresultsdependongettingthebigpicturearchitecture&thedetails(implementationright.(bigpicutre)和實(shí)現(xiàn)availability,modifiability,performance,security,testability,andtimetomarket,cost&benefit,projectedlife,targetmarket,rolloutArchitecturalqualitiesconceptualintegritycorrectness&completenessbuildability概念 Asoftwaresystem’sarchitectureisthesetofprincipaldesigndecisionsaboutthesystem軟件體系結(jié)構(gòu)是系統(tǒng)的最基本決策的集合。Principal”impliesadegreeofimportancethatgrantsadesigndecision“architecturalstatus”“最基本”:設(shè)計(jì)決策在保證體系結(jié)構(gòu)狀態(tài)上的重要性ItimpliesthatnotalldesigndecisionsareThatis,theydonotnecessarilyimpactasystem’sReflectsmajordesigndecisions反映主要的設(shè)計(jì)決策Architectureestablishesthecontextfordesignandimplementation為Rationaleforwhyoneapproachtaken,whatimpactithas選擇的理由和anarchitecturaldesigndecisionAdescriptionofthesetofarchitecturaladditions,subtractionsandmodificationstothesoftwarearchitecture,therationale,andthedesignrules,designconstraintsandadditionalrequirementsthat(partially)realizeoneormorerequirementsonagivenarchitecture.RationaleThereasonsbehindanarchitecturaldesigndecisionItdescribeswhyachangeismadetothesoftwareDesignrulesanddesignconstraintsPrescriptionsforfurtherdesigndecisions.RulesaremandatorydescribedescribetheoppositesideofdesignrulesTheydescribewhatisnotallowedinthefutureofthedesign.非強(qiáng)制性規(guī)定,(什么事不能做)Additionalrequirements額外需求額外設(shè)計(jì)決bythearchitecture.Thesenewrequirementsneedtobeaddressedbyadditionaldesign補(bǔ)充:定義PerryandSoftwareArchitecture={Elements,Form,RationaleWhat基本單位howwhy限“Thearchitectureofasoftwaresystemdefinesthatsystemintermsofcomputationalcomponentsandinteractionsamongthosecomponents.ShawandGarlan96]軟件體系結(jié)構(gòu)定義了系統(tǒng)的計(jì)算部件和部件間的交互部件+連接件+配“Thesoftwarearchitectureofaprogramorcomputingsystemisthestructureorstructuresofthesystem,whichcomprisesoftwarecomponentstheexternallyvisiblepropertiesofthosecomponents,andtherelationshipsamongthem.”[Bass,Clements,andKazman98]軟件體系結(jié)構(gòu)是系統(tǒng)的結(jié)構(gòu),包括了軟件部件+對(duì)外可見(jiàn)屬性+部件間關(guān)Everysoftwarehasoneormorearchitecturestructures有軟件有一理解:參考去年整理軟件體系結(jié)構(gòu)的概高層架包括靜態(tài)和動(dòng)態(tài)屬性指該系統(tǒng)的結(jié)構(gòu),包括軟件組件,及其外部可見(jiàn)屬性,以及組件間的關(guān)系;由計(jì)算件和組件間交互組成組件模塊,包,層,文件,數(shù)據(jù)庫(kù),客戶端,服務(wù)如何定組件的函數(shù)和職責(zé),以及接口必須被定連接器允許組件間交互的構(gòu)造塊(不是簡(jiǎn)單的接口組件連接器包括顯式的和隱式的允許組件間交互的構(gòu)造塊(不是簡(jiǎn)單的接口組件連接器包括顯式的和隱式的,有時(shí)僅僅是一個(gè)通道,有時(shí)包括自己的邏輯和常見(jiàn)連接器(Implicit)事件,C/S中間件,消息和消息總線,共享變量,過(guò)程調(diào)用(本地、遠(yuǎn)程道(Explicit)代理,適配交流表現(xiàn)功能和非功能需求(質(zhì)量)如何被滿質(zhì)量的種類,,,,,商業(yè)質(zhì)量:投放市場(chǎng)的時(shí)間,投入&回報(bào),計(jì)劃周期,目標(biāo)市場(chǎng),首次展出計(jì)劃,遺留系整建筑質(zhì)量:觀念一致性,正確性&完整性,可建造設(shè)計(jì)決策反映設(shè)計(jì)決往往根據(jù)架構(gòu)師的知識(shí)背景實(shí)建立了軟件設(shè)計(jì)和實(shí)現(xiàn)的背景,解釋一種方法被采用的根本原因,它有什么影結(jié)構(gòu)決策是最基本的決策,改變它將會(huì)引起很多連鎖的反使得修改變得容易控制,方便于系統(tǒng)原型的演軟件架構(gòu)是系統(tǒng)的基本組織,包含了它的組件,及其關(guān)系與環(huán)境,以及控制設(shè)計(jì)和演化原4+1View:多視圖模EnduserLogicalProcessPhysicalLogicalView最主要,出發(fā)點(diǎn),需求的映(Object-orientedThesystemisdecomposedintoasetofkeyabstractions,taken(mostly)fromproblemdomainintheformofproblemdomainintheformofobjectsorobjectclasses系統(tǒng)被分解為關(guān)鍵抽象,從問(wèn)題域{Component,connector,configuration}ViewerEnd-user終用considers:Functionalrequirements-Whatthesystemshouldprovideintermsofservicestoitsusers.功能需求,提供給用戶的服務(wù),功能性分析,設(shè)計(jì)決策Thisdecompositionisnotonlyforthesakeoffunctionalanalysis,butalsoservestoidentifycommonmechanismsanddesignelementsacrossthevariouspartsoftheProcess(Theprocessdecomposition)viewer:Integrators集成師considers:Nonfunctionalrequirementsconcurrencyperformancescalability)styleSeveralstyleswouldfitinthisviewGarlanandShawsArchitecturestylesUsesmultiplelevelsofabstractionsalogicalnetworkofprocessesatthehighestlevel多層次抽象性,最高層是進(jìn)城的邏輯網(wǎng)絡(luò)Aprocessisagroupingoftasksthatformanexecutableunit:相關(guān)tasks集結(jié)成可執(zhí)行單元,單獨(dú)進(jìn)程MajorTasks:Arch.relevanttasksMinorTasks:Helpertasks.(Buffering)輔:輔助次DevelopmentBasisofalineofproductThedevelopmentarchitectureofthesystemisrepresentedbymoduleandsubsystemdiagramsshowingtheexport’andimport’relationships.系統(tǒng)分解,產(chǎn)Viewer:ProgrammersandSoftwareManagers開(kāi)發(fā)人員,軟件(Hierarchyoflayers,softwaremanagement,reuse,constraintsoftools)Stylelayeredstyle分層(優(yōu)點(diǎn)每層可以在分解為模Physical(MappingthesoftwaretotheTopology,Thevariouselementsidentified—networks,processes,tasks,andobjects—needtobemappedontothevariousnodes.WeexpectthatseveraldifferentphysicalconfigurationswillbeusedViewer:SystemEngineers系統(tǒng)工程Considers:Non-functionalreq.regardingtounderlyinghardware(availability,(PuttingitallTheelementsinthefourviewsareshowntoworktogetherseamlesslybytheuseofasmallsetofimportantscenarios指揮,連接四個(gè)試圖:,設(shè)Helpillustrateandvalidatethedocument說(shuō)明和驗(yàn)證文GRASP模式GRASPstandsforGeneralResponsibilityAssignmentSoftwareGRASPpatternsfocusononeofthemostimportantaspectsofobjectdesign,assigningresponsibilitiestoclasses.LowHigh見(jiàn)筆記最后一頁(yè)設(shè)計(jì)模式設(shè)計(jì)結(jié)構(gòu)的抽象,針對(duì)疑難點(diǎn),對(duì)原則思想的應(yīng)comprisesclassand/orobject成:類和對(duì)象及其之間的關(guān)系,distillsdesignexperience設(shè)計(jì)過(guò)程中的經(jīng)驗(yàn)總Designpatternshave4essentialProblem:intentcontext,whento解決方案Solution:UML-likestructure,abstract結(jié)果Consequences:resultsand模型:用于封裝與應(yīng)用程序的業(yè)務(wù)邏輯相關(guān)的數(shù)據(jù)模型:用于封裝與應(yīng)用程序的業(yè)務(wù)邏輯相關(guān)的數(shù)據(jù)以及對(duì)數(shù)據(jù)的處理方視圖:負(fù)責(zé)生成用戶界面的部控制器:控制器起到不同層面間的組織作用,用于控制應(yīng)用程序的流1-111模塊結(jié)構(gòu)化的內(nèi)聚與耦合類型參考筆耦合一個(gè)模塊不通過(guò)正常入口轉(zhuǎn)到另一模塊內(nèi)部公共耦合:havereadandwriteaccesstothesameglobal控制耦合:ifmodule1candirectlyaffecttheexecutionofmodule2module1passesa“controlparametertomodule2withlogicalcohesion或者模2返回代碼不僅指示成功或失敗而且指示1(callingmodule)執(zhí)行一些動(dòng)作。(suchaswritinganerrormessageinthecaseoffailure).據(jù)結(jié)構(gòu)或外部變量),或者無(wú)多余的信息被傳遞。舉公共耦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:在實(shí)現(xiàn)中但不在規(guī)格說(shuō)明中SpecificInheritanceModificationinheritancecoupling:無(wú)規(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計(jì)算:如果M個(gè)模塊共享NM*N如果M1個(gè)模塊共享N1個(gè)數(shù)據(jù),M2(M1+M2=M,N1+N2=N)個(gè)模塊共享N2個(gè)數(shù)據(jù),則有作用:Helpsdevelopersandmaintainersofthesystemfindmodulesaffectedbya幫助開(kāi)發(fā)者和維護(hù)者找到被變化影響的模塊.Well-structuredModuleGuideneededtoprovidedevelopmentsupportandtocutdownmaintenancecosts.結(jié)構(gòu)良好的moduleguide可以提供開(kāi)發(fā)支持和減少維護(hù)開(kāi)銷Specifically,foreachmoduletheModuleGuidestatesthesecretsassociatedwitheachmodulePrimarySecret:hiddeninformationthatwasspecifiedtothesoftwaredesignerHiddeninformationcontainedwithinPrimarySecret:hiddeninformationthatwasspecifiedtothesoftwaredesignerHiddeninformationcontainedwithinthemodule.準(zhǔn)備對(duì)外隱藏andasecondarysecretwhichreferstoimplementationdecisionsmadebythedesignerwhenimplementingthemoduledesignedtohidetheprimarysecret.Implementationdecisionsusedtoimplementthetherolesplayedbytheindividualmodulesintheoverallsystemoperation;模塊thefacilitiesprovidedbyeachmodule.ModuleGuideHelpsdevelopersandmaintainersofthesystemfindmodulesaffectedbyachange幫助開(kāi)發(fā)者,維護(hù)者找到被改變影響的模塊ModuleInterfaceDocumentContainspreciseandcompletedescriptionofinterfacetoeachmodule精確完整的描述每個(gè)模塊的接口ModuleDesignDocumentAninternaldesigndocumentforeachimplementationofamodule每個(gè)模塊實(shí)現(xiàn)的內(nèi)部設(shè)計(jì)文檔RequirementsDocumentModuleGuidereferstoitfortherelatedchanges(不考察給代碼的情況,以下內(nèi)容參考去年總結(jié)材料1以模塊為對(duì)象的體系結(jié)構(gòu)風(fēng)InteractionShareData(BlackBoard,InteractionDataFlow(BatchSequential,PipeandFilter)ControlExplicit(CallandMainprogramandChangeinInteractionShareData(BlackBoard,InteractionDataFlow(BatchSequential,PipeandFilter)ControlExplicit(CallandMainprogramandChangeinChanginSpaceTimeReuseMainProgramandSubroutineComponents:Connectors:MainProgramandSubroutineComponents:Connectors:順序系Object-OrientedComponents:Connectors:PipeandFilterArchitecturalPipeandFilterArchitecturalConnectors:Pipe,作為流傳輸?shù)耐ǖ?,把一個(gè)Filter的輸出傳到另一個(gè)的輸入整個(gè)網(wǎng)絡(luò)的正確性不應(yīng)該依賴于Filter的排列順序完全獨(dú)立,可以隨時(shí)增減filter,可以并行開(kāi)發(fā)Implicitinvocation(Eventbased)Componentsagent代理程序(對(duì)Connectors:broadcastConnectors:每個(gè)agent的行為方式:(LayeredComponents:Connectors:LayeredComponents:Connectors:MVCModel:維護(hù)領(lǐng)域模型,并通知View相關(guān)變化Controller:改變model 2以進(jìn)程為對(duì)象的體系2以進(jìn)程為對(duì)象的體系結(jié)構(gòu)風(fēng)格Publish-SubscribeArchitectureConnector:event 以物理單元 以物理單元為對(duì)象的體系結(jié)構(gòu)風(fēng)Client-Three-Tier(N-Tier)DistributedObjectsDistributedResources(http)Client-Components:Connectors:RPC的交互協(xié)議(缺點(diǎn):server設(shè)計(jì)困難,成為瓶頸層:存儲(chǔ)層(或者后端):Peer-to-::舉例:eMuleeDonkey,Gnutella,Freenet,OnShareetc.areexamplesofaP2PDistributedMida(http全局分全局分Globalmovingfromsoftwarerequirementsspecificationtostructuralviewsofthesoftwarearchitecture從軟件需求規(guī)格到軟件體系結(jié)構(gòu)的結(jié)構(gòu)化視圖的過(guò)程步驟:Globalanalysisactivitiesandoneistodesignanddescribethestructureofthesystem.設(shè)計(jì)和描述系統(tǒng)的結(jié)Usefourcomplementaryviewstoreducethecomplexityofdesigningandunderstandingthearchitecture.利用互補(bǔ)的視圖來(lái)減少設(shè)計(jì)和理解體Differentviewshavedifferentengineeringconcerns,sonotallaspectsofthesystemmustbeconsideredatonce.不同視圖有不同關(guān)注點(diǎn),并不ThesecondpartofourapproachisGlobalGlobalAnalysisproducesdocumentationartifactsthatdescribethecontextandrationalefordesigndecisionsGA生描述設(shè)計(jì)決策上下文和Identifytheexternalinfluencingfactorsandcriticalrequirementsthatcouldaffectthearchitecture標(biāo)識(shí)可能影響體系結(jié)構(gòu)的外部影響因素和關(guān)鍵Analyzethemtocomeupwithstrategiesfordesigningthearchitecture2aAnalyzingfactors(constraintsandquality)Three(3)stepStep1:Identifyanddescribethefactors識(shí)別可能影響系統(tǒng)體系結(jié)構(gòu)的需Productfactors:Systemqualityattribute產(chǎn)品因素:質(zhì)量需Organizationalfactors:Businessqualityattribute織因素:業(yè)務(wù)Step2:Describingfactors,CharacterizetheStep2:Describingfactors,CharacterizetheflexibilityorchangeabilityofthefactorsStep3:AnalyzetheimpactofthefactorsfactorThree3stepsprocedure產(chǎn)生issueRelatingfactorstoproblems目的:彌補(bǔ)規(guī)格需求和SA軟件體系結(jié)構(gòu)件的gap差距;重點(diǎn)關(guān)注體系結(jié)構(gòu)設(shè)計(jì)需求(ADR:architecturedesignrequirements)GA:將ADR(SSS:system據(jù)SSS和集中式委派式分散式AcontrolstyleisawaythatdecisionmakingisdistributedamongprogramCentralized—AfewcontrollermakeallsignificantDelegated—DecisionmakingisdistributedthroughtheprogramwithafewcontrollersmakingthemaindecisionsDispersed—Decisionmakingisspreadwidelythroughtheprogramwithfewornocomponentsmakingdecisionsontheirown Collection和實(shí)例Ceae)neIt//clientCeae)neIt//client())Aggreea)emyList=egate(m(=terator(Proxypattern:clientsubject接口交問(wèn)題:提供代理以供其他對(duì)object的訪問(wèn)。遠(yuǎn)程:提供給不同的地址空間的地址的對(duì)象的本地代理虛擬:根據(jù)需求創(chuàng)建開(kāi)銷對(duì)象Subject,realsubjectand用戶subject中定義的抽象方法進(jìn)行操subject的實(shí)現(xiàn)在realsubject和proxy中如果接受到有危險(xiǎn)的調(diào)用,exception或者alarm提Proxy代理了對(duì)于realsubject安全調(diào)用。Clientproxy.Proxy模式引入了對(duì)于對(duì)象的一個(gè)間接的訪問(wèn)方式遠(yuǎn)程proxy隱藏了遠(yuǎn)程的實(shí)現(xiàn)事實(shí)object不在同一地oIteratorfirst(虛擬proxy可以進(jìn)行優(yōu)化,實(shí)際對(duì)象仍存在保護(hù)proxy額外的安全。簡(jiǎn)單,控制,安虛擬proxy可以進(jìn)行優(yōu)化,實(shí)際對(duì)象仍存在保護(hù)proxy額外的安全。簡(jiǎn)單,控制,安全,允許寫(xiě)但是需要迭代器實(shí)現(xiàn))refers pattern:原型類聲明一個(gè)用來(lái)克隆自己的接傳遞拷貝,用原型實(shí)例表示要?jiǎng)?chuàng)建的對(duì)象類型,通過(guò)拷貝為原型創(chuàng)建新的對(duì)象思想:請(qǐng)求后得到拷貝,新的object,每個(gè)請(qǐng)求得到拷貝的不同版本參與者Prototype原型:生命了拷貝自己的接concretePrototype具體原型:clone自己的實(shí)現(xiàn)操客戶:對(duì)原型請(qǐng)求的對(duì)象,通過(guò)請(qǐng)求原型對(duì)象克隆自己來(lái)創(chuàng)建新對(duì)總結(jié):針對(duì)接口編程,而不是實(shí)現(xiàn)繼承允許定義一組有相同接口的對(duì)所有引申類都與基礎(chǔ)類有共享的接所有子類回應(yīng)在其抽象父類接口中的請(qǐng)求LSP:所有類都必須可以被其父類替換,子類可以替代父類存在De-Coupling有哪些手LSP:所有類都必須可以被其父類替換,子類可以替代父類存在De-Coupling有哪些手段Avoidrepetition:doitonce防止避免重重復(fù)意味著耦合,因?yàn)閷?duì)重復(fù)代碼的一塊進(jìn)行改變意味著要改抽象依賴倒置,依賴接口而不是依賴實(shí)抽象不能依賴細(xì)節(jié),細(xì)節(jié)應(yīng)該依賴抽高層模塊不應(yīng)該依賴于底層模塊,二者都應(yīng)依賴于抽在一個(gè)分離模塊即將實(shí)現(xiàn)的模塊中定義接口,基本的方式來(lái)打破依賴和降ehanisdependsMediatorpattern調(diào)停者模式通過(guò)避免對(duì)象互相顯式的指向?qū)Ψ綇亩档婉顔?wèn)題多個(gè)對(duì)象重復(fù)訪問(wèn),無(wú)規(guī)律性一個(gè)對(duì)象集合的交互良好定義,但是交互方式復(fù)雜。通常有非結(jié)構(gòu)依賴對(duì)象復(fù)用困難,因?yàn)閷?duì)象指向和交互很多其他的對(duì)Mediator:定義了與colleague對(duì)象交互的接口,通常被告知事件或者狀concreteMediator:實(shí)現(xiàn)與colleague交互的具體行為,了解和維護(hù)colleaguecolleague道自己Mediator每colleague與其他colleague互時(shí)需要先與自己的mediator互,為mediator供了服務(wù),colleague可能請(qǐng)求相同也可能不同結(jié)果定義對(duì)象,其封裝了一組對(duì)象的交互方 促進(jìn)低耦合,通過(guò)紡織對(duì)象顯示的引用彼此讓人獨(dú)立的拓展其交集中式控 icyMechanisdependMhan.Bridgepattern橋接模式:?jiǎn)栴}常Bridgepattern橋接模式:?jiǎn)栴}常用的處理一個(gè)抽象有多種實(shí)現(xiàn)的方式是繼然而這會(huì)使實(shí)現(xiàn)與抽象進(jìn)行綁并不能夠靈活,可能需要獨(dú)立的修改實(shí)現(xiàn)或參與者Abstraction:定義了抽象RefinedAbstraction:拓展由abstraction定義的接Implementorabstraction了原始操作,abstration提供更加高級(jí)的基于該原始操作的操作。實(shí)現(xiàn)和接口之間解耦合,抽象與實(shí)現(xiàn)獨(dú)立避免了類型檢查,降低了變異的時(shí)間,減少了編譯時(shí)的依賴提高了系統(tǒng)的可擴(kuò)展將實(shí)現(xiàn)細(xì)節(jié)隱藏,用戶不可內(nèi)聚又是可以實(shí)現(xiàn)差異性,接口實(shí)現(xiàn)都可以修改,抽象和實(shí)一個(gè)模塊的信息隱藏有哪兩種基本類型1)每個(gè)模塊有一個(gè)基本外部的行為和內(nèi)部隱每個(gè)模塊隱藏重要的設(shè)計(jì)決策的實(shí)現(xiàn),只有模塊的組成可以了解細(xì)方法:門面模式FacadepatternOCP:模塊可能有附加secrets:secretOCP:Open/closedprinciple開(kāi)關(guān)原則?軟件實(shí)體應(yīng)該對(duì)擴(kuò)展開(kāi)放,對(duì)修改OCP:Open/closedprinciple開(kāi)關(guān)原則?軟件實(shí)體應(yīng)該對(duì)擴(kuò)展開(kāi)放,對(duì)修改關(guān)閉。change方法:策略模式StrategypatternDecoratorpattern適配器模式AdaptorBasicFa?adeAnticipateStrategy如果上下文也有可變性:用橋接模式Beopenforextension,Beclosedfor問(wèn)題 在不修改類代碼的情況Beopenforextension,Beclosedfor問(wèn)題 在不修改類代碼的情況下拓展類的實(shí)例的功用聚合代替繼承,比靜態(tài)的繼承更加靈關(guān)鍵是對(duì)其裝飾的組件來(lái)說(shuō),decorator是透明的,這樣可以嵌套定義結(jié)比繼承更加靈防止繼承樹(shù)堆積過(guò)高而過(guò)于復(fù)有很多類很相似,理解上比較困難,難以理解和調(diào)及其組件并不相同,檢查對(duì)象相似性和相同性可能引起問(wèn)Adapter思想新增加功能使用已有接口時(shí),接口不將類的接口轉(zhuǎn)化為用戶期待讓類共同工作,不受到不兼容接口的影解決結(jié)果靈活性:框架可被開(kāi)發(fā)用來(lái)與不兼容的類協(xié)重用性:現(xiàn)有類實(shí)現(xiàn)的有用功能可以被重類之間的接口協(xié)健壯性:現(xiàn)有類被重用但是不需要修改,防止引入不必要的潛在實(shí)現(xiàn)共性與可變性有哪些手段12StrategypatternPNightTrafficeRushDayTiCyc實(shí)現(xiàn)共性與可變性有哪些手段12StrategypatternPNightTrafficeRushDayTiCycCyclCycle()LightsPolicy*IntersectNextEvent()ChangePolicy(LightsPTrafficStrategy問(wèn)題許多相關(guān)的類只是在其行為表現(xiàn)上不同,strategy提供一種給類配置多種行為的一種Strategy問(wèn)題許多相關(guān)的類只是在其行為表現(xiàn)上不同,strategy提供一種給類配置多種行為的一種一個(gè)雷定義許多行為,這些在其操作中作為多種狀態(tài)條件存需要算法差異性可變性與重用性一組相關(guān)的算法擴(kuò)子類的替代:context類分配為子類,直接給其其差異性復(fù)雜性,難于理好:strategy減少了條件判斷語(yǔ)壞:邏輯分離,用戶必須意識(shí)到是不同的strategy如果復(fù)雜和多種算如果在某些固定特點(diǎn)中有變更的行如果有復(fù)雜的條件判定語(yǔ)問(wèn)題對(duì)象的行為依賴于其狀態(tài):運(yùn)行時(shí)的變更行為依賴于狀解決求concretestateDUIXIANG狀態(tài)決定concreteState類,把自己作為參數(shù)傳遞給Context只提供interface,物具體內(nèi)容,用戶不直接與state切換狀態(tài):context或者concretecontext對(duì)象可以決定concreteState對(duì)象的變結(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ū):如果無(wú)實(shí)舉例:publicinterfaceIState{}PublicclassOffStateIState{PublicvoidswitchFire(FireSwitchsw){sw.setState(newSmallState());}}…3運(yùn)行時(shí)靜態(tài)編譯:共運(yùn)行時(shí)注冊(cè):差異Callbacks:用戶方法,注冊(cè)在服務(wù)器,服務(wù)器可以撤銷。用于拓展的方式。在服務(wù)器的對(duì)象上操Observerpattern:1問(wèn)題定義了對(duì)象間的一對(duì)多的依賴,這樣一個(gè)對(duì)象改變狀態(tài),其依賴被通知并自解決結(jié)果靈活性,可變性和重用性:“event”事件風(fēng)格,低耦更加復(fù)雜:難于理解和測(cè)使用:調(diào)用對(duì)方時(shí)又差異性問(wèn)題,不知對(duì)方狀當(dāng)一個(gè)對(duì)象改變需要改變其他,但不知道要改變的是哪個(gè)對(duì)當(dāng)對(duì)象應(yīng)該通知其他其他對(duì)象,但不假設(shè)其知道哪些對(duì)象。不希望這些對(duì)象緊密耦 Command問(wèn)題專 Command問(wèn)題專門對(duì)對(duì)象進(jìn)行注冊(cè),action處理后交給別人管通過(guò)對(duì)象的行為來(lái)參數(shù)化對(duì)可以在任何時(shí)刻制定,queue隊(duì)列和執(zhí)行通過(guò)存儲(chǔ)context上下文來(lái)支持結(jié)果解耦合了請(qǐng)receiver和可以在?;蛘哧?duì)列中存儲(chǔ)命令:命令處理器模式維護(hù)歷史記容易支持undoredo:必須提供多余的狀態(tài)信息來(lái)防止易于拓展指對(duì)象的創(chuàng)建有哪些常見(jiàn)解決方法簡(jiǎn)單 無(wú)限制的實(shí)例,創(chuàng)建一個(gè)類型,簡(jiǎn)單實(shí)例化和初始CreatorpatternCouplingpatternCohesion復(fù)雜Singletonpattern問(wèn)題:又是需要一個(gè)特定類只有一個(gè)實(shí)解決Constructorprivate:無(wú)法從外部調(diào)生命類的實(shí)例的私有靜態(tài)單解決Constructorprivate:無(wú)法從外部調(diào)生命類的實(shí)例的私有靜態(tài)單寫(xiě)公共的方法或者相似方法,允許對(duì)單個(gè)實(shí)例進(jìn)行訪保護(hù)或者綜合方法來(lái)保證其在多線程程序上可以運(yùn))例publicclassSingletonprivatestaticSingletoninstance=privateSingleton()//}publicstaticSingleton{if(instance==null)instance=new}return}//..其它實(shí)}2(思考題中有)場(chǎng)景3:多種類型,創(chuàng)建類型的差異性SimpleSimplefactory實(shí)例…ct把創(chuàng)建不同pizza的If-else把創(chuàng)建不同pizza的If-elseProduct:定義factorymethod:實(shí)現(xiàn)了Creator:聲明了factorymethod,返回product類型的對(duì)象;也可能定義了factorymentod的缺省實(shí)現(xiàn),返回缺省的concreteproduct類ConcreteCreator:重寫(xiě)factorymehtod,返回一個(gè)concreteproduct的實(shí)例Client需要產(chǎn)生creatorconcreteProduct對(duì)象Factorymethod的例Abstractfactory:指一個(gè)工廠等級(jí)結(jié)構(gòu)可以創(chuàng)建出分屬于不同產(chǎn)品等級(jí)結(jié)構(gòu)的一個(gè)產(chǎn)品目的Factorymethod的例Abstractfactory:指一個(gè)工廠等級(jí)結(jié)構(gòu)可以創(chuàng)建出分屬于不同產(chǎn)品等級(jí)結(jié)構(gòu)的一個(gè)產(chǎn)品目的:為創(chuàng)建一組相關(guān)或者依賴的類型提供接口,但無(wú)需知道其具體類解決abstractFactory:聲明了一個(gè)實(shí)例,該實(shí)例的主要操作是產(chǎn)生singleton初始化,唯一性Abatractproduct:聲明了一個(gè)product對(duì)象的類型的接口,concretefactory產(chǎn)生concreteproductsConcreteproduct:定義了要由對(duì)應(yīng)的concretefactory來(lái)創(chuàng)建product對(duì)象結(jié)果好abstract使交換產(chǎn)品家族容易:只要改變加強(qiáng)products之間的一壞很難支持新類型的產(chǎn)需要重abstractfactory和其子Abstractfactory和Abstractfactory和Prototypepatternp=cloreturncopytfcopyp=cloreturncopytfcopyof 設(shè)計(jì)模式部分所有的思考尋找一個(gè)需要訪問(wèn)集合變量的簡(jiǎn)單場(chǎng)景:編程實(shí)現(xiàn):IteratorPatternandProxy//學(xué)生打印出所有的答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. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 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ì)用戶上傳內(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ì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 網(wǎng)絡(luò)互聯(lián)對(duì)全球化經(jīng)濟(jì)的影響力
- 愛(ài)洗手的好寶寶健康活動(dòng)
- 河南省2024九年級(jí)語(yǔ)文上冊(cè)第五單元19懷疑與學(xué)問(wèn)課件新人教版
- 紅細(xì)胞增多癥的診斷與治療
- 結(jié)核骨影像鑒別病
- 吉林省2024七年級(jí)數(shù)學(xué)上冊(cè)第2章整式及其加減2.4整式的加減4.整式的加減課件新版華東師大版
- 黃瓜生長(zhǎng)期枯萎病與防治
- 骨傷科的治療方法
- 氧化碳制取的研究的說(shuō)課稿
- 紅樓夢(mèng)說(shuō)課稿
- 化驗(yàn)室化學(xué)試劑分類清單(參考模板)
- 三教”統(tǒng)一、和諧發(fā)展促進(jìn)學(xué)生健康成長(zhǎng)的有效方式
- 材料成型概論 第四章 擠壓成型
- 六盤水氣候特征
- 輻射安全責(zé)任書(shū)
- 第五章水輪機(jī)特性曲線
- 職業(yè)病防治(課堂PPT)
- 建設(shè)工程項(xiàng)目施工安全評(píng)價(jià)書(shū)(共10頁(yè))
- 機(jī)場(chǎng)助航燈光設(shè)計(jì)講解
- fairytale傳奇英文版歌詞
- 消毒記錄臺(tái)賬
評(píng)論
0/150
提交評(píng)論