正 文

利用UML序列图设计Java应用程序详解


www.7dspace.com  更新日期:2005-12-19 5:40:57  七度空间


/*
* Flooring.java
*
*/

class Flooring {

private static final double limit = 0.02; // limit for one more width

private String name; // for identification purposes

private double price; // price per meter

private double widthOfFlooring; // meter

public Flooring(String initName, double initPrice, double initWidth) {

name = initName;

price = initPrice;

widthOfFlooring = initWidth;

}

public String getName() {

return name;

}

public double getPricePerM() {

return price;

}

public double getWidth() {

return widthOfFlooring;

}

/*
* We are going to calculate the amount which is needed to cover one surface.
* The flooring is always placed crosswise relative to the length of the surface.
* If you want to find the amount the other way, you have to change
* width and length in the surface argument.
*/

public double getNoOfMeters(Surface aSurface) {

double lengthSurface = aSurface.getLength();

double widthSurface = aSurface.getWidth();

int noOfWidths = (int)(lengthSurface / widthOfFlooring);

double rest = lengthSurface % widthOfFlooring;

if (rest >= limit) noOfWidths++;

return noOfWidths * widthSurface;

}

public double getTotalPrice(Surface aSurface) {

return getNoOfMeters(aSurface) * price;

}

}

以上三个类之间的类图关系可以表示为如下图:

以下我们来详细分析类FlooringClient是如何发送消息给其它类,而实现方法的调用过程。并如何用UML序列图来描述这一序列过程。

5页,页码:[1] [2] [3] [4] [5] 

上一篇:用装饰者(Decorator)模式添加功能
下一篇:用递归来优化JavaScript代码
作者:龚赤兵  来源:开发者在线 ( 责任编辑:7dspace )
收藏此页】【打印】【关闭
站 内 搜 索
 

热 点 导 读
特 别 推 荐