中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

使用IntelljIDEA生成接口的類繼承圖

2018-07-20    來(lái)源:importnew

容器云強(qiáng)勢(shì)上線!快速搭建集群,上萬(wàn)Linux鏡像隨意使用

類圖生成方法

以一個(gè)裝飾器模式實(shí)現(xiàn)數(shù)學(xué)運(yùn)算的例子為例。

1、安裝 Intellj Ultimate , lience server: http://xdouble.cn:8888/

2、在類上右鍵點(diǎn)擊 class diagram :

3、在得到的類的框框上 “雙指單擊”或右鍵 , 選擇 show Implementations :

4、得到的實(shí)現(xiàn)類列表上, Ctrl + A 全選

5、Enter 得到類圖結(jié)果,上面有 導(dǎo)出圖片功能。

6、可以查看接口及實(shí)現(xiàn)類的覆寫方法

7、調(diào)整布局

8、添加額外的類
如果發(fā)現(xiàn)還有點(diǎn)單獨(dú)的接口有關(guān)聯(lián)但是不在上述繼承體系里, 可以添加額外的 class diagram 并按上如法炮制。

9、導(dǎo)出圖片保存

裝飾器代碼

Function.java 函數(shù)接口, sources 是被裝飾的內(nèi)層函數(shù)運(yùn)算。

package zzz.study.patterns.decorator.func;

public abstract class Function {

    protected Function[] sources;

    public Function(Function[] sources) {
        this.sources = sources;
    }

    public Function(Function f) {
        this(new Function[] {f});
    }

    public abstract double f(double t);

    public String toString() {
        String name = this.getClass().toString();
        StringBuffer buf = new StringBuffer(name);
        if (sources.length > 0) {
            buf.append('(');
            for (int i=0; i < sources.length; i++) {
                if (i > 0)
                    buf.append(",");
                buf.append(sources[i]);
            }
            buf.append(')');
        }
        return buf.toString();
    }
}

Constant.java :常量函數(shù)

package zzz.study.patterns.decorator.func;

public class Constant extends Function {

    private double constant;

    public Constant() {
        super(new Function[] {});
    }

    public Constant(double constant) {
        super(new Function[]{});
        this.constant = constant;
    }

    public double f(double t) {
        return constant;
    }

    public String toString() {
        return Double.toString(constant);
    }

}

T.java : 線性函數(shù)

package zzz.study.patterns.decorator.func;

public class T extends Function {

    public T() {
        super(new Function[] {});
    }

    public double f(double t) {
        return t;
    }

    public String toString() {
        return "t";
    }

}

Square.java :平方函數(shù)

package zzz.study.patterns.decorator.func;

public class Square extends Function {

    public Square() {
        super(new Function[] {});
    }

    public Square(Function f) {
        super(new Function[] {f});
    }

    public double f(double t) {
        return Math.pow(sources[0].f(t),2);
    }

    public String toString() {

        StringBuffer buf = new StringBuffer("");
        if (sources.length > 0) {
            buf.append('(');
            buf.append(sources[0]);
            buf.append('^');
            buf.append(2);
            buf.append(')');
        }
        return buf.toString();
    }

}

ExpDouble.java :指數(shù)函數(shù)

package zzz.study.patterns.decorator.func;

public class ExpDouble extends Function {

    private double  expDouble;  // 指數(shù)的底數(shù)

    public ExpDouble() {
        super(new Function[] {});
    }

    public ExpDouble(double expDouble, Function f) {
        super(new Function[] {f});
        this.expDouble = expDouble;
    }   

    public double f(double t) {
        return Math.pow(expDouble, sources[0].f(t));
    }

    public String toString() {

        StringBuffer buf = new StringBuffer("");
        if (sources.length > 0) {
            buf.append('(');
            buf.append('(');
            buf.append(expDouble);
            buf.append(')');
            buf.append('^');
            buf.append(sources[0]);
            buf.append(')');
        }
        return buf.toString();
    }

}

Pow.java :冪函數(shù)

package zzz.study.patterns.decorator.func;

public class Pow extends Function {

    private double  pow;  // 冪函數(shù)的指數(shù)

    public Pow() {
        super(new Function[] {});
    }

    public Pow(Function f, double pow) {
        super(new Function[] {f});
        this.pow = pow;
    }   

    public double f(double t) {
        return Math.pow(sources[0].f(t), pow);
    }

    public String toString() {

        StringBuffer buf = new StringBuffer("");
        if (sources.length > 0) {
            buf.append('(');
            buf.append(sources[0]);
            buf.append('^');
            buf.append('(');
            buf.append(pow);
            buf.append(')');
            buf.append(')');
        }
        return buf.toString();
    }  
}

Arithmetic.java :四則運(yùn)算

package zzz.study.patterns.decorator.func;

public class Arithmetic extends  Function {

    protected char op;

    public Arithmetic(char op, Function f1, Function f2) {
        super(new Function[] {f1, f2});
        this.op = op;
    }

    public double f(double t) {
        switch(op) {
            case '+':
                return sources[0].f(t) + sources[1].f(t);
            case '-':
                return sources[0].f(t) - sources[1].f(t);
            case '*':
                return sources[0].f(t) * sources[1].f(t);
            case '/':
                return sources[0].f(t) / sources[1].f(t);
            default:
                return 0;
        }
    }

    public String toString() {

        StringBuffer buf = new StringBuffer("");
        if (sources.length > 0) {
            buf.append('(');
            buf.append(sources[0]);
            buf.append(Character.toString(op));
            buf.append(sources[1]);
            buf.append(')');
        }
        return buf.toString();

    }

}

Sin.java , Cos.java 請(qǐng)讀者自行完成。

測(cè)試:

package zzz.study.patterns.decorator;

import zzz.study.patterns.decorator.func.Arithmetic;
import zzz.study.patterns.decorator.func.Cos;
import zzz.study.patterns.decorator.func.Function;
import zzz.study.patterns.decorator.func.Sin;
import zzz.study.patterns.decorator.func.Square;
import zzz.study.patterns.decorator.func.T;

public class ShowFunction {

    public static void main(String[] args) {
        Function complexFunc = new Arithmetic('+', new Square(new Sin(new T())), new Square(new Cos(new T())));
        System.out.println(complexFunc + " = " + complexFunc.f(100.0));

    }
}

在?《Java函數(shù)接口實(shí)現(xiàn)函數(shù)組合及裝飾器模式》?一文中,使用 Function 接口有更簡(jiǎn)潔的裝飾器模式實(shí)現(xiàn)。

標(biāo)簽: 代碼

版權(quán)申明:本站文章部分自網(wǎng)絡(luò),如有侵權(quán),請(qǐng)聯(lián)系:west999com@outlook.com
特別注意:本站所有轉(zhuǎn)載文章言論不代表本站觀點(diǎn)!
本站所提供的圖片等素材,版權(quán)歸原作者所有,如需使用,請(qǐng)與原作者聯(lián)系。

上一篇:linux 定時(shí)休眠

下一篇:詳解 equals() 方法和 hashCode() 方法