欢迎访问昆山宝鼎软件有限公司网站! 设为首页 | 网站地图 | XML | RSS订阅 | 宝鼎邮箱 | 后台管理


新闻资讯

MENU

软件开发知识

pow); } public String toString() { StringBuffer buf = new S

点击: 次  来源:劳务派遣管理系统 时间:2018-07-18

原文出处: 琴水玉

类图生成要领

以一个装饰器模式实现数学运算的例子为例。

1、安装 Intellj Ultimate ,劳务派遣管理系统, lience server: http://xdouble.cn:8888/

2、在类上右键点击 class diagram :

 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 :四则运算 package zzz.study.patterns.decorator.func;public class Arithmetic extends Function { protected char op; public Arithmetic(char op

3、在获得的类的框框上 “双指单击”或右键 , 选择 show Implementations :

 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 :四则运算 package zzz.study.patterns.decorator.func;public class Arithmetic extends Function { protected char op; public Arithmetic(char op

4、获得的实现类列表上, Ctrl + A 全选

 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 :四则运算 package zzz.study.patterns.decorator.func;public class Arithmetic extends Function { protected char op; public Arithmetic(char op

5、Enter 获得类图功效,昆山软件开发,上面有 导出图片成果。

 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 :四则运算 package zzz.study.patterns.decorator.func;public class Arithmetic extends Function { protected char op; public Arithmetic(char op

6、可以查察接口及实现类的覆写要领

 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 :四则运算 package zzz.study.patterns.decorator.func;public class Arithmetic extends Function { protected char op; public Arithmetic(char op

7、调解机关

 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 :四则运算 package zzz.study.patterns.decorator.func;public class Arithmetic extends Function { protected char op; public Arithmetic(char op

8、添加特另外类
假如发明尚有点单独的接口有关联可是不在上述担任体系里, 可以添加特另外 class diagram 并按上如法炮制。

9、导出图片生存

装饰器代码

Function.java 函数接口, sources 是被装饰的内层函数运算。

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 :常量函数

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 : 线性函数

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 :平方函数

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 :指数函数

package zzz.study.patterns.decorator.func;

public class ExpDouble extends Function {

    private double  expDouble;  // 指数的底数

    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();
    }

}