您的位置:首页 > 其它

交通管理系统----面向对象的分析与设计:

2013-12-11 21:45 239 查看
             交通管理系统----面向对象的分析与设计:

 

面向对象的分析与设计:

谁拥有数据,谁就对外提供操作这些数据的方法!

典型案例:

1.人在黑板上画圆    对象有:person, blakboard, circle  其中 画圆这个动作draw()是圆身上的动作!原因是:画圆需要圆心和半径,这都是圆上的数据

2.列车司机紧急刹车  对象有:司机和列车   其中 刹车这个动作 是车上的动作

3.售货员正在统计售货小票上的总金额   对象有:售货员 和小票  其中 统计总金额是小票上的方法

4.两块石头磨成一把石刀,石刀可以砍树,砍成木材,木材做成椅子!

其中对象有:stone, stoneKnife.tree.material,chair

stoneKdnife=KnifeFactory.createKnife(stone,stone);

material=stoneKnife.cut(tree);

chair=ChairFactory.makeChair(material);

 

 

5.球从一根绳子的一段移动到了另一端!

class Rope{

   private Point start;

   private Point end;

   public Rope(Point start,Point end){

     This.start=start;

     This.end=end;

 }

  public Point nextPoint(Point currentPont){

  }

}

class Ball{

   private Rope rope;

   private Point currentPoint;

   public Ball(Rope rope,Point startPont){

      this.rope=rope;

       this.currentPoint=startPont;

   }

public void move(){

   currentPoint=rope.nextPont(currentPoint);

   System.out.println(“小球移动到了”+currentPoint);

 }

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: