使用反射 api 测量 Class 的位置稳定性
Measure the Positional stability of a Class using reflection api
作为大学项目的一部分,我们需要“创建一个 Java 应用程序,该应用程序使用反射来分析任意 Java 应用程序存档 (JAR) 并计算每个文件的位置稳定性对象图中的组件 classes 回想一下,类型的位置稳定性 (I) 可以通过计算进入和离开该类型的依赖项的数量来衡量:”。
我们需要测量每个 class 及其组件的传出和传入耦合,然后计算稳定性。
我对如何计算传入和传出耦合有点困惑。这是我到目前为止所做的,
for (int i = 0; i < cls.size(); i++) {
Class cla = cls.getMyClass(i);
Class[] interfaces = cla.getInterfaces();
for(Class inter : interfaces){
efferentCoup++;
}
Constructor[] cons = cla.getConstructors();
Class[] conParams;
for(Constructor c: cons){
conParams = c.getParameterTypes();
for(Class par: conParams){
efferentCoup++;
}
}
Field[] fields = cla.getFields();
for(Field fie: fields ){
efferentCoup++;
}
}
- 传入耦合:- 衡量有多少其他 class 使用
具体class。
To calculate this you need to introspect all packages and increment
your counter everytime, that specific class is getting referenced.
- 传出耦合:- 是衡量有多少不同的 classes
由特定 class
使用
To calculate this you need to introspect through a particular class
and see how many other classes it is referencing to.
理想情况下,第 1 步应该足以计算两个耦合。
作为大学项目的一部分,我们需要“创建一个 Java 应用程序,该应用程序使用反射来分析任意 Java 应用程序存档 (JAR) 并计算每个文件的位置稳定性对象图中的组件 classes 回想一下,类型的位置稳定性 (I) 可以通过计算进入和离开该类型的依赖项的数量来衡量:”。
我们需要测量每个 class 及其组件的传出和传入耦合,然后计算稳定性。
我对如何计算传入和传出耦合有点困惑。这是我到目前为止所做的,
for (int i = 0; i < cls.size(); i++) {
Class cla = cls.getMyClass(i);
Class[] interfaces = cla.getInterfaces();
for(Class inter : interfaces){
efferentCoup++;
}
Constructor[] cons = cla.getConstructors();
Class[] conParams;
for(Constructor c: cons){
conParams = c.getParameterTypes();
for(Class par: conParams){
efferentCoup++;
}
}
Field[] fields = cla.getFields();
for(Field fie: fields ){
efferentCoup++;
}
}
- 传入耦合:- 衡量有多少其他 class 使用 具体class。
To calculate this you need to introspect all packages and increment your counter everytime, that specific class is getting referenced.
- 传出耦合:- 是衡量有多少不同的 classes 由特定 class 使用
To calculate this you need to introspect through a particular class and see how many other classes it is referencing to.
理想情况下,第 1 步应该足以计算两个耦合。