240 likes | 1.08k Views
Stepwise Refinement. A program design strategy where a solution is first described in terms of high level functions, then each function is broken down into details that are refined in successive steps until the whole program is fully defined. This PPT originated with Dr. Roland Untch.
E N D
Stepwise Refinement • A program design strategy where a solution is first described in terms of high level functions, then each function is broken down into details that are refined in successive steps until the whole program is fully defined. This PPT originated with Dr. Roland Untch.
Stepwise Refinement helps us write “good” programs • Stepwise Refinement tells us not to delve into details too quickly, but to gradually solve the problem by breaking it into smaller sub-problems. • Each sub-problem is then solved (also using stepwise refinement.) • Eventually our solutions are expressed in detailed terms.
9 9 8 8 7 7 6 6 5 5 4 4 3 3 2 2 1 1 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 Other Harvest Task Designs
Which harvest design is better? Can you think of other designs?
We might solve the harvest problem as follows: #include <karel.h> using namespace std; int main() { TurnOn(); Move(); HarvestARow(); TurnLeft(); Move(); TurnLeft(); HarvestARow(); TurnRight(); Move(); TurnRight(); HarvestARow(); // can you finish the coding??? // more code goes here….. }
What are the new commands that you used in your design?? The command HarvestARow(); is a new command, so the next step is to write this command. We might write the first new command as: void HarvestARow() { PickBeeper(); Move(); PickBeeper(); Move(); PickBeeper(); Move(); PickBeeper(); Move(); PickBeeper(); }
What other new commands (to Karel) did you use? We need to write those as well?
Stepwise Refinement(another definition) • The software design technique that aims to describe functionality at a very high level, then partition it repeatedly into more detailed levels (one level at a time) until the detail is sufficiently refined to express directly as code. • Also called top-down design.