OO的代码作业到这里要告一段落了,以后可以少熬夜多睡觉了,撒花~~~
一、调研
(1)总结介绍规格化设计的大致发展历史
->落后的软件生产方式无法满足迅速增长的计算机软件需求,软件的开发与维护出现一系列严重问题。
->由此提出结构化程序设计,以模块化设计为中心,分而治之,引出了规格化抽象。
->软件系统日趋复杂,结构化程序设计的缺点日渐暴露出来,面向对象由此产生,规格化设计进一步发展。
->设计模式、设计原则、架构模式的产生。
(2)为什么得到了人们的重视
因为OO这门课的要求,不写会被扣很多分
规格化的书写和设计有助于程序员理解程序、分解程序,独立化开发任务、加快开发速度,有助于程序在细节和整体上进行验证,以保证程序的正确性,提高程序未来的可维护性、可扩展性。当在团队开发时,规格化的设计更有利于团队中的人相互理解。
二、分析bug
- 第九次作业
没有功能bug和规格bug
- 第十次作业
功能bug:

规格bug:

- 第十一次作业
没有规格bug
三、分析自己规格bug产生的原因
课下发放的JSF示例并不能完全解决我们对于规格的理解,所以在编写程序规格时难免出现一些问题,归结原因还是不熟练以及缺乏类似的思想。
四、列举不好的写法并给出改进写法
boolean getflag() {
/**
* @REQUIRES: None
* @MODIFIES: None
* @EFFECTS: \result == flag;
*/
return flag;
}
-------------------------------------------------------------------------------------------
改进:
/**
* @EFFECTS: \result == flag;
*/
synchronized void driving(int i) {//有目的行驶
/**
* @REQUIRES:None;
* @MODIFIES:
* \this.newlocation;
* @EFFECTS:
* 首先更新last,然后根据输入更新location
* @THREAD_REQUIRES:
* \locked(\this);
* @THREAD_EFFECTS:
* \locked();
*/
if (i == 1) newlocation = location - 80;
else if (i == 2) newlocation = location + 80;
else if (i == 3) newlocation = location - 1;
else if (i == 4) newlocation = location + 1;
}
--------------------------------------------------------------------------------------------
改进:
/**
* @REQUIRES:1 <= i <= 4;
* @MODIFIES:
* \this.newlocation;
* @EFFECTS:
* (i == 1) ==> (\this.newlocation == \this.location - 80);
* (i == 2) ==> (\this.newlocation == \this.location + 80);
* (i == 3) ==> (\this.newlocation == \this.location - 1);
* (i == 4) ==> (\this.newlocation == \this.location + 1);
* @THREAD_REQUIRES:
* \locked(\this);
* @THREAD_EFFECTS:
* \locked();
*/
synchronized boolean checkconnected(int newLocation) {//检测道路连通性
/**
* @REQUIRES:None;
* @MODIFIES:None;
* @EFFECTS:
* \all int next;next belongs to map.edges[location] && next!=newLocation;
* \result==false;
* \exists int next;next belongs to map.edges[location] && next==newLocation;
* \result==true;
*/
Vector<Integer> temp = map.edges[location];
for (int next : temp){
if (next == newLocation) return true;
}
return false;
}
--------------------------------------------------------------------------------------------
改进:
/**
* @REQUIRES:0 <= newLocation <= 6399;
* @MODIFIES:None;
* @EFFECTS:
* (\all int next;next belongs to map.edges[location] && next!=newLocation) ==> (\result==false);
* (\exists int next;next belongs to map.edges[location] && next==newLocation ==> (\result==true);
*/
synchronized void addflow(int start, int end) {
/**
* @REQUIRES:
* 0<=start<=6399;
* 0<= end <=6399;
* @MODIFIES:
* \this.flow;
* @EFFECTS:
* 如果start与end邻接,则
* \this.flow[start][end]++;
* \this.flow[end][start]++;
* 否则不做任何操作
* @THREAD_REQUIRES:
* \locked(\this);
* @THREAD_EFFECTS:
* \locked();
*/
if(edges[start].contains(end)) {
int dx = Math.abs(start/80-end/80);
int dy = Math.abs((start-end)%80);
if ((dx == 1 && dy == 0) || (dx == 0 && dy == 1)) {
flow[start][end]++;
flow[end][start]++;
}
}
}
----------------------------------------------------------------------------------------
改进:
/**
* @REQUIRES:
* 0<=start<=6399;
* 0<= end <=6399;
* @MODIFIES:
* \this.flow;
* @EFFECTS:
* (edges[start].contains(end)) ==>
* \this.flow[start][end]++ &&
* \this.flow[end][start]++;
* @THREAD_REQUIRES:
* \locked(\this);
* @THREAD_EFFECTS:
* \locked();
*/
synchronized void setflow(int start, int end, int value) {
/**
* @REQUIRES:
* None;
* @MODIFIES:
* \this.flow;
* @EFFECTS:
* \this.flow[start][end] == value;
* \this.flow[end][start] == value;
* @THREAD_REQUIRES:
* \locked(\this);
* @THREAD_EFFECTS:
* \locked();
*/
flow[start][end] = value;
flow[end][start] = value;
}
--------------------------------------------------------------------------------------------
改进:
/**
* @REQUIRES:
* 0<=start<=6399;
* 0<= end <=6399;
* 0<= value <=100;
* @MODIFIES:
* \this.flow;
* @EFFECTS:
* \this.flow[start][end] == value;
* \this.flow[end][start] == value;
* @THREAD_REQUIRES:
* \locked(\this);
* @THREAD_EFFECTS:
* \locked();
*/
五、功能bug与规格bug在方法上的聚集关系
根据上述对作业bug的分析,功能bug和规格bug没有什么聚集关系,但是这种情况出现的原因主要是是先写完的代码才写的规格,导致两个描述可能不太一致,但是从整个程序的设计来考虑,当一个方法的规格复杂时,必然需要更多的篇幅和代码来进行实现,出现bug的几率也会越大。
六、归纳自己在设计规格和撰写规格的基本思路和体会
由于并不是在一开始写代码就书写规格,而是在写完代码以后才补充规格,导致我觉得这几次的规格书写没什么用,反而还让我陷入了因为要补写规格所以debug的时间大大减少程序bug增多的僵局。不过从长远来看,规格训练是必要的,根据规格书写代码确实能减少写代码过程中的很多问题。这个也确实还需要练习。
佛系oo挺好的,拿不出真凭实据从gui上找错报别人一堆bug,申诉没说两句话就“有什么问题直接仲裁吧”。我六系同学最需要学习的不是怎么写代码,是怎么和别人沟通和交流,这个课的互测阶段真的把我的好脾气耗尽了...
来源:https://www.cnblogs.com/qinfeng918/p/9101817.html