通过Java程序来反映各种类型的耦合、内聚-金初阳9.pdfVIP

  • 7
  • 0
  • 约1.34万字
  • 约 11页
  • 2018-05-19 发布于贵州
  • 举报

通过Java程序来反映各种类型的耦合、内聚-金初阳9.pdf

通过Java程序来反映各种类型的耦合、内聚-金初阳9

通过Java程序来反映各种类型的耦合、内聚 耦合性是用来描述模块之间的独立程度。这里讲模块之间的耦合程度分为六个程度R0-R5 (RiRj,ij)。分别是无耦合,数据耦合,标记耦合,控制耦合,共同耦合,内容耦合。  无耦合R0:模块X与模块Y没有交互  数据耦合R1:模块X与模块Y之间有调用关系,传递的是简单的数据值,相当于高级语言的 值传递。一个模块访问另一个模块时,彼此之间是通过简单数据参数(不是控制参数、公共 数据结构或外部变量)来交换输入、输出信息的。 代码模拟: packagemetrics.coupling.data; importmetrics.coupling.data.Person; publicclassMain { publicstaticvoidmain(String[]args) { Personperson=newPerson(1.8,56); doubleheight=person.getHeight(); doubleweight=person.getWeight(); doubleBMI=BMIUtils.getBMI(height,weight); System.out.println(BMI:+BMI); } } packagemetrics.coupling.data; publicclassPerson { privatedoubleheight; privatedoubleweight; publicPerson(doubleheight,doubleweight) { super(); this.height=height; this.weight=weight; } publicPerson() { super(); //TODOAuto-generatedconstructorstub } publicdoublegetHeight() { returnheight; } publicvoidsetHeight(doubleheight) { this.height=height; } publicdoublegetWeight() { returnweight; } publicvoidsetWeight(doubleweight) { this.weight=weight; } } packagemetrics.coupling.data; publicclassBMIUtils { publicstaticdoublegetBMI(doubleheight,doubleweight) { returnweight/(Math.pow(height,2)); } }  标记耦合R2:模块X与模块Y之间传递的是数据结构 (复合数据类型),一般是指传的 是改数据的地址。 代码模拟: packagemetrics.coupling.stamp; importmetrics.coupling.stamp.BMIUtils; importmetrics.coupling.stamp.Person; publicclassMain { publicstaticvoidmain(String[]args) { Personperson=newPerson(1.8,56); doubleBMI=BMIUtils.getBMI(person); System.out.println(BMI:+BMI); } } packag

文档评论(0)

1亿VIP精品文档

相关文档