Group project
Suppose these three dogs are working on a group project:
Lucky | Dusty | Ned |
They get together to write the main program. Here it is:
Then they break up to work on their subs individually. Lucky writes getInput
, Dusty writes computeShipping
, and Ned writes outputWebPage
. Since they have the signatures of each sub, their subs shouldn't step on each other.
But… how can Dusty write computeShipping
, when Lucky hasn't finished getInput
?
Fake subs
That's where stubs come in. They're fake subs, that have the same signature as a real sub, without the actual code.
Dusty is writing the processing code, which can't run without data from getInput
. So she writes a stub:
Now she can write and test computeShipping
. She can change the constants in the stub, to see how computeShipping
runs.
Ned, who's writing the output sub, writes a stub for computeShipping
. Then he can get on with his work.
When they're all done, they can put their subs together, and test the whole program.
Summary
A stub is a fake sub. It has the same signature as a real sub, without the actual code.