zoukankan      html  css  js  c++  java
  • 面向过程及面向对象的扇入及扇出

    面向过程的扇入及扇出:

    扇入:是指直接调用该模块的上级模块的个数。即:called by个数 (在McCabe 里度量名称为Fan in)

    扇出:该模块直接调用的下级模块的个数。即:calls to 个数(在McCabe 里度量名称为Fan out)

    面向对象的扇入及扇出:

    扇入:派生类的数量:即一个子类继承的父类个数。通俗的讲即有多个个父类产生了此子类。(在McCabe 里度量名称为Fan in)

    扇出:由一个类衍生出类的数量:即一个父类产生的子类个数。(在McCabe 里度量名称为NOC)

    实例代码:

    父类:People.java

     1 public class People {
     2     private String name;
     3     private int age;
     4     
     5     public People(String myName,int myAge){
     6         this.name = myName;
     7         this.age = myAge;
     8     }
     9     
    10     public void eat(){
    11         System.out.println("I am eating");
    12     }
    13     
    14     public void sleep(){
    15         System.out.println("I am sleep");
    16     }
    17     
    18     public void doWork(){
    19         this.eat();
    20         this.sleep();
    21         System.out.println("I am goto work");
    22     }
    23     
    24 }
    View Code

     子类1:Students.java

     1 public class Students extends People{
     2     private String mySchool;
     3 
     4     public Students(String myName, int myAge, String mySchool) {
     5         super(myName, myAge);
     6         // TODO Auto-generated constructor stub
     7         this.mySchool = mySchool;
     8     }
     9     
    10     public void goSchool(){
    11         this.doWork();
    12         System.out.println("I am goto school");
    13     }
    14 }
    View Code

    子类2:Worker.java

     1 public class Worker extends People{
     2     private String address;
     3 
     4     public Worker(String myName, int myAge,String address) {
     5         super(myName, myAge);
     6         // TODO Auto-generated constructor stub
     7         this.address = address;
     8     }
     9     
    10     public void doJob(){
    11         this.doWork();
    12         System.out.println("I am goto job");
    13     }
    14 }
    View Code

    主类:Famly.java

    public class Famly {
    
        public static void main(String[] args) {
            // TODO Auto-generated method stub
            Students stu = new Students("xx",15,"qinghua");
            Worker wor = new Worker("yy",35,"tonghuashun");
            
            stu.goSchool();
            wor.doWork();
        }
    
    }
    View Code

    使用McCabe分析的类调用关系图:

    People父类产生了子类Students 及Worker,故People类的扇出NOC为2,Students及Worker类的扇入Fan in为1。

    McCabe度量信息截图如下:

    使用McCabe分析模块调用关系图如下:

    doWork方法调用了eat方法及sleep方法,故doWork方法的扇出为2,因doWork方法也调用了类方法system.out.println故:doWork的扇出为3;

    同理eat方法及sleep方法的扇入为1,扇出为1。

    使用McCabe分析如下:

    针对eat模块扇入扇出分析如下:

    针对doWork模块扇入扇出分析如下:

  • 相关阅读:
    Stone Game, Why are you always there? HDU
    SG函数
    A New Stone Game POJ
    卡特兰数
    找单词 HDU
    排列组合 HDU
    Harry And Magic Box HDU
    GCD and LCM HDU
    Co-prime HDU
    线段树——F
  • 原文地址:https://www.cnblogs.com/feiqixia/p/11220463.html
Copyright © 2011-2022 走看看