【文档说明】软件工程实践者研的究方法课件.ppt,共(39)页,645.129 KB,由小橙橙上传
转载请保留链接:https://www.ichengzhen.cn/view-45064.html
以下为本文档部分文字说明:
1Chapter10Component-LevelDesignSoftwareEngineering:APractitioner’sApproach,7/ebyRogerS.PressmanEvaluationonly.edwithA
spose.Slidesfor.NET3.5ClientProfile5.2Copyright2004-2011AsposePtyLtd.2WhatisaComponent?OMGUnifiedMo
delingLanguageSpecification[OMG01]definesacomponentas“…amodular,deployable,andreplaceablepartofasystemthatencapsulatesimplementa
tionandexposesasetofinterfaces.””OOview:acomponentcontainsasetofcollaboratingclassesConventionalview:acomponentcontainsprocessinglogic,theinternal
datastructuresthatarerequiredtoimplementtheprocessinglogic,andaninterfacethatenablesthecomponenttobeinvokedanddatatobepassedtoit.Evaluatio
nonly.edwithAspose.Slidesfor.NET3.5ClientProfile5.2Copyright2004-2011AsposePtyLtd.3OOComponentPrintJobcomputeJobinitiate
JobnumberOfPagesnumberOfSidespaperTypepaperWeightpaperSizepaperColormagnificationcolorRequirementsproductionFeaturescollationOptionsbindingOptionsco
verStockbleedprioritytotalJobCostWOnumberPrintJobcomputePageCost()computePaperCost()computeProdCost()com
puteTotalJobCost()buildWorkOrder()checkPriority()passJobtoProduction()elaborateddesignclass<<interface>>computeJobcomputePageCost
()computePaperCost()computeProdCost()computeTotalJobCost()<<interface>>initiateJobbuildWorkOrder()checkPr
iority()passJobtoProduction()designcomponentnumberOfPagesnumberOfSidespaperTypemagnificationproductio
nFeaturesPrintJobcomputeJobCost()passJobtoPrinter()analysisclassEvaluationonly.edwithAspose.Slidesfor.NET3.5ClientProfile5.2Copyri
ght2004-2011AsposePtyLtd.4ConventionalComponentEvaluationonly.edwithAspose.Slidesfor.NET3.5ClientProfile5.2Copyright2004-20
11AsposePtyLtd.5ConventionalComponentComputePageCostdesigncomponentaccessCostsDBgetJobDataelaboratedmodulePageCostin:jobsizein:color=1,2,3,4
in:pageSize=A,B,C,Bout:BPCout:SFin:numberPagesin:numberDocsin:sides=1,2in:color=1,2,3,4in:pagesize=A,B,C,Bout:pagecostjobsize(JS)=numberPage
s*numberDocs;lookupbasepagecost(BPC)-->accessCostsDB(JS,color);lookupsizefactor(SF)-->accessCostDB(JS,color,size)jo
bcomplexityfactor(JCF)=1+[(sides-1)*sideCost+SF]pagecost=BPC*JCFgetJobData(numberPages,numberDocs,sides,color,pageSiz
e,pageCost)accessCostsDB(jobSize,color,pageSize,BPC,SF)computePageCost()Evaluationonly.edwithAspose.Slidesfor.NET3.
5ClientProfile5.2Copyright2004-2011AsposePtyLtd.6BasicDesignPrinciplesOpen-ClosedPrinciple(开闭原则).“Amodule[component]shouldbe
openforextensionbutclosedformodification.SubstitutionPrinciple(替换原则).“Subclassesshouldbesubstitutablefortheirba
seclasses.DependencyInversionPrinciple(依赖倒置原则).“Dependonabstractions.Donotdependonconcretions(具体实现).”InterfaceSegregationPrinc
iple(接口分离原则).“Manyclient-specificinterfaces(专用接口)arebetterthanonegeneralpurposeinterface.ReleaseReuseEquivalencyPrinciple(发布复用等价原则).“Thegran
ule(粒度)ofreuseisthegranuleofrelease.”CommonClosurePrinciple(共同封装原则).“Classesthatchangetogetherbelongtogether.(同时变更的类应封装在一起)”CommonReusePrinci
ple(共同重用原则).“Classesthataren’treusedtogethershouldnotbegroupedtogether.”Evaluationonly.edwithAspose.Sli
desfor.NET3.5ClientProfile5.2Copyright2004-2011AsposePtyLtd.7DesignGuidelinesComponentsNamingconven
tionsshouldbeestablishedforcomponentsthatarespecifiedaspartofthearchitecturalmodelandthenrefinedandelaboratedasp
artofthecomponent-levelmodelInterfacesInterfacesprovideimportantinformationaboutcommunicationandcollaboration(aswellashelpingustoachievetheOPC)De
pendenciesandInheritanceitisagoodideatomodeldependenciesfromlefttorightandinheritancefrombottom(der
ivedclasses)totop(baseclasses).Evaluationonly.edwithAspose.Slidesfor.NET3.5ClientProfile5.2Copyright2004-2011AsposeP
tyLtd.8Cohesion(内聚度)Conventionalview:the“single-mindedness”ofamoduleOOview:cohesionimpliesthatacomponentorclassencapsulatesonlyattr
ibutesandoperationsthatarecloselyrelatedtooneanother.Levelsofcohesion(内聚度依次递减)FunctionalLayerComm
unicationalSequentialProceduralTemporal设计目标:模块内各动作的内聚度越高越好。Evaluationonly.edwithAspose.Slidesfor.NET3.5ClientProfile5.2Copyrigh
t2004-2011AsposePtyLtd.9Coupling(耦合度)Conventionalview:ThedegreetowhichamoduleisconnectedtoothermodulesandtotheexternalworldOOview:aqualitative
measureofthedegreetowhichclassesareconnectedtooneanotherLevelofcoupling(耦合度依次递减)ContentCommonControlDataRoutinecallExter
nal设计目标:模块之间的耦合度越底越好。Evaluationonly.edwithAspose.Slidesfor.NET3.5ClientProfile5.2Copyright2004-2011AsposePtyLt
d.10ComponentLevelDesign-IStep1.Identifyalldesignclassesthatcorrespondtotheproblemdomain.Step2.Identifyalldesignclassesthatcorrespo
ndtotheinfrastructuredomain.(forexample,GUIcomponent,OScomponents)Step3.Elaboratealldesignclassesthatarenotacquiredasreusablecomponents,includ
ingthemessage,interface,attributeandoperation.Step3a.Specifymessagedetailswhenclassesorcomponentcollabo
rate.(CollaborationDiagramwithmessagesisshown)Evaluationonly.edwithAspose.Slidesfor.NET3.5ClientProfile5.2Copyright20
04-2011AsposePtyLtd.11ComponentLevelDesign-IStep3b.Identifyappropriateinterfacesforeachcomponent.下图为PrintJob重构类和接
口定义Step3c.Elaborateattributesanddefinedatatypesanddatastructuresrequiredtoimplementthem.Evaluationonly.edwithAspose.Slidesfor.NE
T3.5ClientProfile5.2Copyright2004-2011AsposePtyLtd.12Component-LevelDesign-IIStep3d.Describeprocessingflowwithineachoperati
onindetail.实例:右图为ComputePaperCost()操作的ActivityDiagram.Evaluationonly.edwithAspose.Slidesfor.NET3.5ClientProfile5.2Copyright2
004-2011AsposePtyLtd.13Component-LevelDesign-IIIStep4.Describedatasources(database)andidentifytheclassesrequiredtomanagethem.S
tep5.Developandelaboratebehavioralrepresentationsforaclassorcomponent.(右图为PrintJob类的StateChart)Step6.Elaboratedeploymentdiagr
amstoprovideadditionalimplementationdetail.Evaluationonly.edwithAspose.Slidesfor.NET3.5ClientProfile5.2Copyright2004-
2011AsposePtyLtd.14AlgorithmDesignModelrepresentsthealgorithmatalevelofdetailthatcanbereviewedforqualityoptions:decisiontable/treegra
phical(e.g.flowchart,boxdiagram)PAD(ProgramAnalysisDiagram)pseudocode(e.g.PDL)Evaluationonly.edwithAspose.Slidesfor.NET3.5
ClientProfile5.2Copyright2004-2011AsposePtyLtd.15DecisionTableConditionsregularcustomersilvercustomergoldcustomerspecialdiscountRul
esnodiscountapply8percentdiscountapply15percentdiscountapplyadditionalxpercentdiscountTFTTTTTF13564FTTT2RulesEvaluationonly.edwith
Aspose.Slidesfor.NET3.5ClientProfile5.2Copyright2004-2011AsposePtyLtd.11/24/202216FlowchartEvaluationonly.edwithAspose.Slidesfor.NET3.5ClientProfil
e5.2Copyright2004-2011AsposePtyLtd.17NS(Box)DiagramEvaluationonly.edwithAspose.Slidesfor.NET3.5ClientProfile5.2Copyright2004-2011AsposePtyL
td.18ProgramAnalysisDiagram(PAD)Evaluationonly.edwithAspose.Slidesfor.NET3.5ClientProfile5.2Copyright2
004-2011AsposePtyLtd.19ProgramAnalysisDiagram(PAD)例:模块binary(x,v,n,p)完成判断一个特定值x是否出现在已经按递增顺序排好序的数组v中。如果存在则返回相应下标m
id,否则返回值-1。Evaluationonly.edwithAspose.Slidesfor.NET3.5ClientProfile5.2Copyright2004-2011AsposePtyLtd.20ProgramDes
ignLanguage(PDL)if-then-elseifconditionxthenprocessa;elseprocessb;endifPDLeasytocombinewithsourcecodemachinereadable,noneedforgraphi
csinputgraphicscanbegeneratedfromPDLenablesdeclarationofdataaswellasprocedureeasiertomaintainEvaluationonly.edwithAspose.Slidesfor.NET3.5ClientProfi
le5.2Copyright2004-2011AsposePtyLtd.11/24/202221ProgramDesignLanguage(PDL)Evaluationonly.edwithAspose.Slidesfor.NET3.5ClientProfile5.2Copyright
2004-2011AsposePtyLtd.22StepwiseRefinementopenwalktodoor;reachforknob;opendoor;walkthrough;closedoor.r
epeatuntildooropensturnknobclockwise;ifknobdoesn'tturn,thentakekeyout;findcorrectkey;insertinlock;endifpull/pushdoormoveoutofway
;endrepeatEvaluationonly.edwithAspose.Slidesfor.NET3.5ClientProfile5.2Copyright2004-2011AsposePtyLtd.23DesigningConventionalCom
ponentsThedesignofprocessinglogicisgovernedbythebasicprinciplesofalgorithmdesignandstructuredprogrammingThe
designofdatastructuresisdefinedbythedatamodeldevelopedforthesystemThedesignofinterfacesisgovernedbythecollaborationsthatacomponentmu
steffectEvaluationonly.edwithAspose.Slidesfor.NET3.5ClientProfile5.2Copyright2004-2011AsposePtyLtd.24AlgorithmDesigntheclosestdesignactivit
ytocodingtheapproach:reviewthedesigndescriptionforthecomponentusestepwiserefinementtodevelopalgorithmus
estructuredprogrammingtoimplementprocedurallogicuse„formalmethods‟toprovelogicEvaluationonly.edwithAspose.Slide
sfor.NET3.5ClientProfile5.2Copyright2004-2011AsposePtyLtd.11/24/202225Y逐步求精方法示例:骑士周游问题。给出一块有n2个格子的棋盘。一位骑士放在初始坐标为(
x0,y0)的格子里,然后按照国际象棋的规则移动。问题是找到一种可以走遍整个棋盘的方案(如果这种方案存在),即计算一个n2-1次移动的周游,使得棋盘上每一个格子恰好被走过(访问过)一次。(1)数据结构设计:棋盘:用一个二维整型数组h[i,j
],i=1..n,j=1..n马的移动位置:有8个可走位置。马的初始位置为(x,y),下一个移动位置(x+a[k],y+b[k]),其中k=1..8。棋盘格子h[x,y]是否被访问过,可以用下面的方式记录:3241马586
7ka[k]b[k]1212123-124-215-2-16-1-271-282-1X0PDL描述举例0表示格子[x,y]未被访问过i表示格子[x,y]在第i次移动中被访问过,1<=i<=n2h[x,y]=Evaluationonly.edwithAspose.Sl
idesfor.NET3.5ClientProfile5.2Copyright2004-2011AsposePtyLtd.11/24/202226(2)算法设计:试探+回溯步1:初始化;步2:对给定的马的当前位置调用“试探下步移动”;步3:if下步移动成功then步
3.1:打印移动结果;else步3.2:打印无解ednif“初始化”细化为:1.1马的8个可移动位置的差值分别按照前面表格中的值预先放在a、b数组中;1.2棋盘h[i,j]在马未访问过时应该都预先放入0;1.3马的最初位置可以是(1,1);此时该位置
所确定的棋盘格子认为被访问过,因此应有h[1,1]=1。步3中对“下步移动成功”的判断可以对步2中“试探下步移动”即过程try(i,x,y,q)调用结果的返回值q作判断即可:q为true即为移动成功,q为false即为移动失败。步3.1“
打印移动结果”即输出数组h[i,j]的各元素之值。其中i,j的取值为1到n;步3.2“打印无解”即是输出一个提示信息。PDL描述举例Evaluationonly.edwithAspose.Slidesfor.NET3.5ClientP
rofile5.2Copyright2004-2011AsposePtyLtd.11/24/202227(2)算法设计:试探+回溯步1:初始化;步2:对给定的马的当前位置调用“试探下步移动”;步3:if下步移动成功then步3.1:打印移动结果;else步3.2:打印无解。e
ndif对于马的当前位置的下步移动应该有8个候选位置用K计数,候选次序是前面图示中的逆时针方向进行。一旦进入下一步即一个新的位置,同样又要“试探下步移动”。如果本步移动成功,那么返回“真”,否则返回“假”。因此是一个递归过程try(i,x,y,q)。“试探下
步移动”可设为try(i,x,y,q):2.0做候选准备;2.1repeat2.1.1从下一步移动表中挑选出下一步候选者;2.1.2if候选者可接受then进行移动;endif2.2until移动成功或再无候选者;2.3返回移动成功与否的标志.马在当前位置而且在下步移动前,一个位置都
没有试探过,因此k值应为0。8个候选位置试探完毕时k值应为8。PDL描述举例Evaluationonly.edwithAspose.Slidesfor.NET3.5ClientProfile5.2Copy
right2004-2011AsposePtyLtd.“试探下步移动”还需要细化:2.0做候选准备;2.1repeat2.1.1从下一步移动表中挑选出下一步候选者2.1.2如果候选者可接受,则2.1.2.1进行移动;2.2until移动成功或再无候选者;2.3返
回移动成功与否的标志.如果候选者的当前步为k,则候选者的下一步变为k+1。下一步的候选者“可接受”的条件应该是:u,v不能越界而且该步所处位置未被访问过,可表示为(1<=u<=n)and(1<=v<=n)and(h[u,v]=0)2.1.2.1“进行移动”可以进一步细化为:记录移动;if盘未走遍t
hen“试探下步移动”即为递归调用步2;if“试探下步移动”不成功then删去这一记录即回溯;else用局部变量q1表示并赋true;endifendif设挑出的下一步候选者为(u,v),则u用x+a[k],v用y+b[k]替换。“移动成功”可把ture赋予局部
变量q1;“再无候选者”意味着当前马的位置的下一步已经对可能的8个位置都试完了,因此可表示为k=8。移动成功与否可把变量q1的值赋予变量qPDL描述举例Evaluationonly.edwithAspose.Slidesfor.
NET3.5ClientProfile5.2Copyright2004-2011AsposePtyLtd.11/24/2022292.1.2.1“进行移动”还需要细化:记录移动;if盘未走遍then“试探下步移动”即为递归
调用步2;if“试探下步移动”不成功then删去这一记录;else给q1赋值true;endifendif“记录移动”可以表示为:h[u,v]被赋予当前所试探的次数i。i是一个全局变量“盘未走遍”可以表示为:i<n2“试探下步移动”应该是一个递归
调用,可以表示为:try(i+1,x,y,q1)“试探下步移动不成功”可以表示为:NOTq1“删去这一记录”可以表示为:h[u,v]被赋予0PDL描述举例Evaluationonly.edwithAspose.Slidesfor.NET3.5ClientProfile5.2Copy
right2004-2011AsposePtyLtd.11/24/202230PRAGRAMKNIGHTSTOUR//第1步:定义变量并初始化DECLAREn:asinteger;q:asboolean;GET(n);DO-WHILEi<=nDO-WHILEj<=nh[i,j]=0;j=j
+1;ENDDOi=i+1;ENDDO;a[1]=2;b[1]=1;a[2]=1;b[2]=2;a[3]=-1;b[3]=2;a[4]=-2;b[4]=1;a[5]=-2;b[5]=-1;a[6]=-1;b[6]=-2;a[7]=1;b[7]=-2;a[8]=
2;b[8]=-1;//第2步:试探下步移动h[1,1]=1;try(2,1,1,q);//调用过程//第3步:输出结果IFqTHENDO-WHILEi<=nDO-WHILEj<=nPUT(h[i,j]);j=j+1;ENDDO换行;i=i+1;E
NDDOELSEPUT(“打印无解”);ENDIFENDPROG基于PDL描述获得最终算法//递归过程定义PROCEDUREtry(i,x,y,q)DECLAREi,x,y:asintegerARG;q:asbooleanARG;k=0;REPEATUNTILk=8or
q1k=k+1;q1=FALSE;u=x+a[k];v=y+b[k];IF((1≤u≤n)and(1≤v≤n)and(h[u,v]=0))THENtry(i+1,u,v,q1);IFNOTq1THENh[u,v]=0ELSEq1=TRUE;ENDIFENDIF
ENDREPq=q1;ENDPROCEvaluationonly.edwithAspose.Slidesfor.NET3.5ClientProfile5.2Copyright2004-2011AsposePtyLtd.31Component-Ba
sedDevelopmentWhenfacedwiththepossibilityofreuse,thesoftwareteamasks:Arecommercialcomponentsavailabletoimplementtherequirem
ent?Areinternally-developedreusablecomponentsavailabletoimplementtherequirement?Aretheinterfacesforavailablecomponentscompatiblew
ithinthearchitectureofthesystemtobebuilt?Evaluationonly.edwithAspose.Slidesfor.NET3.5ClientProfile5.2Copyright2004-2011AsposePtyLtd.
32Component-BasedSEalibraryofcomponentsmustbeavailable.componentsshouldhaveaconsistentstructure.astandardshouldexist,e.g.,OMG/CORBAM
icrosoftCOMSunJavaBeansEvaluationonly.edwithAspose.Slidesfor.NET3.5ClientProfile5.2Copyright2004-2011A
sposePtyLtd.33OMG/CORBATheObjectManagementGrouphaspublishedacommonobjectrequestbroker(代理)architecture(OMG/CORBA).Anobjectrequestbroker(ORB
)providesservicesthatenablereusablecomponents(objects)tocommunicatewithothercomponents.Objectswithintheclient
applicationrequestoneormoreservicesfromtheORBserver.Requestsaremadedynamicallyatruntime.Aninterfacecontainsall
necessaryinformationabouttheservice’srequestandresponseformats.Evaluationonly.edwithAspose.Slidesfor.NET3.5ClientProfile5.2Copyrigh
t2004-2011AsposePtyLtd.CORBA架构图34Evaluationonly.edwithAspose.Slidesfor.NET3.5ClientProfile5.2Copyright2004-2011AsposePtyLtd.基于CORBA的技术架构实例统一接入平台的技术架构
图35Evaluationonly.edwithAspose.Slidesfor.NET3.5ClientProfile5.2Copyright2004-2011AsposePtyLtd.36MicrosoftCOMThecomponentobjectmodel(COM)providesa
specificationforusingcomponentsproducedbyvariousvendors(供应商)withinanapplicationrunningundertheWindowsoperatingsys
tem.COMencompassestwoelements:COMinterfaces(implementedasCOMobjects)asetofmechanismsforregisteringandpassingmessagesbetweenCOMinterfaces.Ev
aluationonly.edwithAspose.Slidesfor.NET3.5ClientProfile5.2Copyright2004-2011AsposePtyLtd.组件对象模型(COM)COM是微软对网页服务器与客户端、应
用系统与Office软件间互动的一项组件技术。COM可以被应用于多种平台上(不限于Windows)。COM提供跟程序语言无关的方法实现一个组件,因此可以在其他环境中执行。COM要求组件遵照一个共同的界面
,该界面与操作内容无关。COM组件由以Win32动态连接库(DLL)或可执行文件(EXE)形式发布的可执行代码组成。遵循COM规范编写出来的组件将能够满足对组件架构的所有要求。COM组件可以给应用程序、操作系统以及其他组件提供服务;自定义的COM组件可以在运行时刻同其他组件连接起来构成
某个应用程序;COM组件可以动态的插入或卸出应用。37Evaluationonly.edwithAspose.Slidesfor.NET3.5ClientProfile5.2Copyright2004-2011AsposePtyLtd.38SunJ
avaBeansTheJavaBeanscomponentsystemisaportable,platformindependentCBSEinfrastructuredevelopedusingtheJavaprogrammingl
anguage.TheJavaBeanscomponentsystemprovidesasetoftools,calledtheBeanDevelopmentKit(BDK),thatallowsd
eveloperstoanalyzehowexistingBeans(components)workcustomize(定制)theirbehaviorandappearanceestablishmechanismsforcoordinationandcommunicationdeve
lopcustomBeansforuseinaspecificapplicationtestandevaluateBeanbehavior.Evaluationonly.edwithAspose.Slidesfor.NET3
.5ClientProfile5.2Copyright2004-2011AsposePtyLtd.JavaBeanArchitecture39Evaluationonly.edwithAspose.Slidesfor.NET3.5ClientProfile5.2
Copyright2004-2011AsposePtyLtd.