Design
Creating any application can be broken up into three phases: designing, developing, and debugging. We've gone over aspects of all three in our previous labs, but now it's time to put on your thinking cap and delve deeper into the wonderful world of design.
A good design is crucial in creating a program that not only solves your problem, but also does in an extensible way. As your programs get larger and larger, design becomes even more important in keeping your code readable and understandable. We've provided you will a lot of information on how to design program over the course of semester, let's review: A poor design could make implementation near impossible.
Goal: Review techniques for designing programs by going through a thorough design for a chess game.
General Introduction to Design
The very first step of program design is gathering requirements. Think of this step as creating a creating a checklist for your program. During this stage you want to answer the following questions: What is the program required to do? What is the overall goal of the program? How does it work? What should it do in various situations? How does the user interact with it? In the real world, companies often do industry research and usability testing to understand what their users expect from a program and how they expect to interact with its features. For CS15, you can usually just play with demos and read the assignment handouts to determine the requirements.
Let's go back to LiteBrite. The requirements for LiteBrite were pretty simple:
- There should be a grid and palette in the main application window.
- There should be at least 3 color buttons in the palette.
- When a user clicks on the grid, a light show up in that spot with the currently selected color.
- A user can select another color by clicking on one of the other color buttons in the palette.
- If the user clicks on the currently selected color button, nothing changes.
- If the user clicks on the "Exit" button, the program closes.
- If the user clicks on an existent light, the light will be replaced with a new light colored with the currently selected color.
Sometimes you will also run into situations where you need to prioritize your requirements. Most of the time you can think of 3 different rankings:
- Must implement, will fail project/won't get full credit if I don't.
- Desirable and somewhat easy to implement, extra credit.
- Crazy Extra Credit! Bells and Whistles!
Prioritizing requirements is especially helpful in keeping you on track when developing larger programs, you can regularly check the list and measure what you can accomplish given your time constraints and plan accordingly. For example, you should make sure your priority 1 requirements are working before you go on to priority 2, so if putting color buttons break your Cartoon 2 hours before the deadline, you should be able to easily take that code out and hand in the working version with just the priority 1 level implemented.
NOTE: Sometimes, higher priority features cannot be added if you didn't plan for them ahead. So if you want to add something really cool, like a timed animation, make sure to design for it before starting to code! This way, if you have time to implement it, you won't have to redesign and rewrite your entire program. This mean spending more time in the designing phase, but it will save you a lot of time in the future!