Designing programs
To explain the difference between the old, or procedural, way of designing
a program and the OO approach, allow me to compare it to the process for
making a nice pot of tea.
Presenting procedural design — from goals to action
Procedural programming is the most straightforward way of programming.
Each segment of code focuses on achieving a step toward a goal. In the case
of making a pot tea, you can think of these steps as filling a vessel with water,
boiling the water, and pouring the water.
This example began with a nice gift of fancy leaf tea, from India. Not having
made tea from leaves before, I called my mom, and she gave me the following
steps:
1. Turn on the faucet.
2. Put enough water in a kettle for the number of cups you want to make.
3. Put the kettle on the stove.
4. Turn on the stove.
5. For each cup, put a teaspoon of tea leaves in the teapot.
6. When the water boils, pour the water from the kettle into the teapot.
7. Let the tea steep for five minutes.
8. Pour the tea into each cup.
9. Enjoy!
And that’s how a typical procedural program works, the kind people wrote
before OO came into vogue. You had a problem to solve and a set of steps for
solving the problem.
The recipe is presented in pseudo (simulated) programming language.
But it illustrates the concepts used in writing a real program.
No comments:
Post a Comment