last modified 2/28/01
Modular Programming
Recommended Reading:
Sedgewick pages 166-171
1. Interface
- defines data structure
- declares functions to be used to manipulate data structure
2. Implementation
- actual code for the functions declared in interface
- you may have more than one implementation for the same interface
3. Client
- a program that uses functions declared in interface (without 'knowledge'
of how they are implemented or of underlying data structure)
- multiple, separate clients can use the same interface
Questions from Students
- What is a "debug" client?
- A debug client
tests each of the functions provided in the interface. As you write the
code for ("implement") each function in the interface, test it
with a debug client.
- What are the benefits of "changing implementation without having to
change programs"?
- Imagine you have to write
a tremendously long program in which you need to use the square root of
numbers throughout the code (and the library function sqrt() doesn't
exist). Now, if you had put the code for the bisection method in your
program every time you needed to do this, it would have been a big task to
go back at some later time and changed to the Newton method.
Alternatively, if you had had the foresight to write sqrt() as a separate
function, you could have changed it in only one place. This is not only
less time consuming, but also less error-prone. Those are some of the
benefits. (Note: this is an older question...the first programming
assignment used to be a program that calculated square roots using
both the Bisection method and Newton's method.)
main page