Interface Versus Implementation

As you've learned, clients are the parts of the program that create and use objects of your class. You can think of the interface to your class—the class declaration—as a contract with these clients. The contract tells what data your class has available and how your class will behave.

For example, in the Cat class declaration, you create a contract that every Cat will know and be able to retrieve its own age, that you can initialize that age at construction and set it or retrieve it later, and that every Cat will know how to Meow().

If you make GetAge() a const function (as you should), the contract also promises that GetAge() won't change the Cat on which it is called.

Why Use the Compiler to Catch Errors?

The harsh reality of programming is that none of us writes perfectly bug-free code. What separates the professional from the hobbyist is not that the professional's code is perfect; it is that the bugs are found before the product ships, not after.

Compile-time errors—that is, errors found while you are compiling—are far better than runtime errors— errors found while you are executing the program.

Compile-time errors can be found much more reliably. It is possible to run a program many times without going down every possible code path. Therefore, a runtime error can hide for quite awhile. Compile-time errors are found every time you compile, so they are easier to identify and fix. It is the goal of quality programming to ensure that the code has no runtime bugs. One tried-and-true technique to accomplish this is to use the compiler to catch your mistakes early in the development process.

Of course, your code can be perfectly legal but not do what you intend. That is why you still need a Quality Assurance team.


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
52.15.74.25