岁月联盟 · 中国技术网 本站主页 | 安全认证 | 用户服务 | 技术论坛
新闻快报 | 新手学堂 | 黑客特区 | 程序语言 | 数 据 库 | 防 火 墙 | 路由交换 | 系统集成 | 服 务 器 | 存储备份 | 考试认证
Windows | Linux | Java | 协议分析 | 问题解答 | 进程大全 | 网页设计 | 多 媒 体 | 图库资料 | 软件下载 | 站内下载
  您现在的位置: 岁月联盟 >> Java >> 高级技术 >> UML/OO >> Java正文
利用UML序列图设计Java应用程序详解
作者:未知 文章来源:本站整理 点击数: 更新时间:2007-7-22 17:52:04

  Java应用程序由许多类所构成,是Java实现面向对象应用程序的核心。类图主要描述Java应用程序中各种类之间的相互静态关系,如类的继承、抽象、接口以及各种关联。要利用UML设计Java应用程序,仅仅使用类图来描述这些静态关系,利用可视化工具,要实现Java应用程序的代码自动生成,是远远不够的。我们还必须描述各种类相互之间的协作关系、动态关系,如时间序列上的交互行为。其中UML序列图就是用来描述类与类之间的方法调用过程(或消息发送)是如何实现的。
  本文通过一个具体的应用程序的设计与实现过程,详细说明了利用UML序列图设计Java应用程序,使得开发过程标准化、可视化,代码编程简单化。
  我们要设计的应用程序FlooringClient是用来计算在一定面积的表面上贴上规格化的地板砖或墙纸所需要的地板砖或墙纸材料的长度和价钱。该程序涉及到三个类:FlooringClient、Surface以及Floor。其各自的类图以及程序代码分别如下
  
 

  /*
  
  * FlooringClient.java
  
  *
  
  */
  
  class FlooringClient {
  
  public static void main(String[] args){
  
  Surface theSurface=new Surface("Margaret's Floor",5,6);
  
  Flooring theFlooring=new Flooring("Fitted carpet",24.50,5);
  
  double noOfMeters=theFlooring.getNoOfMeters(theSurface);
  
  double price=theFlooring.getTotalPrice(theSurface);
  
  System.out.println("You need "+noOfMeters+" meters,price$ "+price);
  
  }
  
  }
  
  
 

  /*
  * Surface.java
  *
  */
  class Surface {
  
  private String name; // for identification purposes
  
  private double length;
  
  private double width;
  
  public Surface(String initName, double initLength, double initWidth) {
  
  name = initName;
  
  length = initLength;
  
  width = initWidth;
  
  }
  
  public String getName() {
  
  return name;
  
  }
  
  public double getLength() {
  
  return length;
  
  }
  
  public double getWidth() {
  
  return width;
  
  }
  
  public double getArea() {
  
  return width * length;
  
  }
  
  public double getCircumference() {
  
  return 2 * (length + width);
  
  }
  
  }
  
  
 

  /*
  
  * 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++;

[1] [2] 下一页


  • 上一个Java:
  • 下一个Java:
  •  
    热门文章
    推荐文章
    关于我们 | 发展历程 | 网站地图 | 广告服务 | 招贤纳士 | 战略合作 | 友情链接 | 著作声明 | 联系我们
    Copyright © 2002-2007 SYUE All rights reserved.
    E_mail:Admin@Syue.Com 皖ICP备05004589号
    未经授权禁止转载、摘编、复制或建立镜像.如有违反,追究法律责任.
    传世私服 传奇世界私服 天龙八部私服 bet365 传世私服 天龙八部私服 热血江湖私服 英雄合击传奇私服 热血江湖私服 bet365 bet365