简体   繁体   English

使用反射API测量类的位置稳定性

[英]Measure the Positional stability of a Class using reflection api

As part of a project for college we are required to " create a Java application that uses reflection to analyse an arbitrary Java Application Archive (JAR) and calculates the positional stability of each of the component classes in its object graph Recall that the Positional Stability (I) of a type can be measured by counting the number of dependencies that enter and leave that type:". 作为大学项目的一部分,我们需要“创建一个Java应用程序,该应用程序使用反射来分析任意Java应用程序存档(JAR),并在其对象图中计算每个组件类的位置稳定性。回想一下,位置稳定性( I)的类型可以通过计算进入和离开该类型的依赖项的数量来度量:“。

We need to measure the Efferent and Afferent couplings of each class and it components, then calculate the stability. 我们需要测量每个类及其组件的传出和传入耦合,然后计算稳定性。

I am a little confused at how to calculate the Afferent and Efferent couplings. 我对如何计算传入和传出耦合有些困惑。 This is what I have done so far, 这是我到目前为止所做的

 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++;
        }
}
  • Afferent Couplings :- is a measure of how many other classes use the specific class. 传入耦合 :-衡量有多少其他类使用特定类。

To calculate this you need to introspect all packages and increment your counter everytime, that specific class is getting referenced. 要计算此值,您需要对所有程序包进行内部检查并每次都增加计数器,即已引用该特定类。

  • Efferent couplings :- is a measure of how many different classes are used by the specific class 传出耦合 :-衡量特定类使用了多少个不同的类

To calculate this you need to introspect through a particular class and see how many other classes it is referencing to. 要计算此值,您需要对特定的类进行自省,并查看它所引用的其他几个类。

Ideally step 1, should be good enough to calculate both couplings. 理想情况下,步骤1应该足以计算两个耦合。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM