软件工程II(管理)_第三次作业(更正版)
Homework: Measuring Cohesion<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
Calculate the functional cohesion measures for the following code fragment
<?xml:namespace prefix = v ns = "urn:schemas-microsoft-com:vml" /><shapetype id="_x0000_t75" coordsize="21600,21600" o:spt="75" o:preferrelative="t" path="m@4@5l@4@11@9@11@9@5xe" filled="f" stroked="f"><stroke joinstyle="miter"></stroke><formulas><f eqn="if lineDrawn pixelLineWidth 0"></f><f eqn="sum @0 1 0"></f><f eqn="sum 0 0 @1"></f><f eqn="prod @2 1 2"></f><f eqn="prod @3 21600 pixelWidth"></f><f eqn="prod @3 21600 pixelHeight"></f><f eqn="sum @0 0 1"></f><f eqn="prod @6 1 2"></f><f eqn="prod @7 21600 pixelWidth"></f><f eqn="sum @8 21600 0"></f><f eqn="prod @7 21600 pixelHeight"></f><f eqn="sum @10 21600 0"></f></formulas><path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect"></path><lock v:ext="edit" aspectratio="t"></lock></shapetype><shape id="Picture_x0020_6" style="VISIBILITY: visible; WIDTH: 171pt; HEIGHT: 210pt" o:spid="_x0000_i1025" type="#_x0000_t75" alt="tu0709" o:allowoverlap="f"><imagedata src="file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtml1/01/clip_image001.png" o:title="tu0709"></imagedata></shape>
Answer:
Graph, under showed, showing the dependencies between the variables in the code in last example. Use solid lines for data dependencies and dashed lines for control dependencies.
<shape id="_x0000_i1027" style="WIDTH: 443.25pt; HEIGHT: 231.75pt" type="#_x0000_t75"><imagedata src="file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtml1/01/clip_image003.jpg" o:title="untitled"></imagedata></shape>
Total tokens = 5;
Glue tokens = 2;
Superglue tokens = 1;
Weak functional cohesion (WFC) = glue tokens / total tokens = 2/5 = 0.4;
Strong functional cohesion (SFC) = superglue tokens / total tokens = 1/5 = 0.2;
Adhesiveness = (0.4+0.2)/2 = 0.3;
Homework
1. Given the following design, indicate for the following ideas of coupling, cohesion, and abstraction whether it is desirable to have a high or low value and how this design exemplifies the term
<shape id="Picture_x0020_5" style="VISIBILITY: visible; WIDTH: 372pt; HEIGHT: 154.5pt" o:spid="_x0000_i1028" type="#_x0000_t75" alt="tu0716" o:allowoverlap="f"><imagedata src="file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtml1/01/clip_image005.png" o:title="tu0716"><font color="#000000"></font></imagedata></shape>
Answer:
根据上述代码可知:
由于把Course类对象直接定义为College类的成员属性,所以这两个类之间的耦合度很高。
虽然Course类中有不少成员方法,但没有一个成员方法使用到该类的成员属性,所以Course类模块的聚合度很低。
并且,这两个类中存在大量可共用的成员变量以及很多功能重复的成员方法。
建议将程序修改为:
Base.java
package com;
public abstract class Base
{
public String courseNum ;
}
Student.java
package com;
public class Student extends Base
{
private String stuID;
private String name;
public String getStuID() {}
public void setStuID(String stuID) {}
public String getName() {}
}
Course.java
public class Course extends Base
{
public List stuList ;
public void displayStudentsInCourse(){}
public void addStudent(Student stu){}
}
College.java
package com;
import java.util.List;
public class College
{
public List courseList ;
public void addCourse(Course course){} ;
public void displayStudent(String stuName){} ;
}
2. Draw scenarios for the interaction between a customer trying to buy a particular music CD with cash and a clerk in the music store. Be sure to cover all possibilities. Use the state machine model with the events being the arcs.
Answer:
<shapetype id="_x0000_t75" coordsize="21600,21600" o:spt="75" o:preferrelative="t" path="m@4@5l@4@11@9@11@9@5xe" filled="f" stroked="f"><font color="#000000"><stroke joinstyle="miter"></stroke></font><formulas><f eqn="if lineDrawn pixelLineWidth 0"></f><f eqn="sum @0 1 0"></f><f eqn="sum 0 0 @1"></f><f eqn="prod @2 1 2"></f><f eqn="prod @3 21600 pixelWidth"></f><f eqn="prod @3 21600 pixelHeight"></f><f eqn="sum @0 0 1"></f><f eqn="prod @6 1 2"></f><f eqn="prod @7 21600 pixelWidth"></f><f eqn="sum @8 21600 0"></f><f eqn="prod @7 21600 pixelHeight"></f><f eqn="sum @10 21600 0"></f></formulas><path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect"></path><lock v:ext="edit" aspectratio="t"></lock></shapetype><shape id="_x0000_i1025" style="WIDTH: 474.75pt; HEIGHT: 387.75pt" type="#_x0000_t75"><imagedata src="file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtml1/01/clip_image001.jpg" o:title="Interaction1"><font color="#000000"></font></imagedata></shape>