4.6. Overriding

As an abstract base, Payment is pretty limited in its current state. You can only overload methods in the class; that is, you can add new methods that have the same name as existing methods. However, existing behavior cannot be redefined. Note that different payment types need to implement Authorize, Bill, and Credit in different ways. Credit cards and checks are authorized through outside companies. However, while credit-card billing is handled by one of those same outside companies, billing a check means that Racer Jim gets an email and the checks are taken down to the bank. Finally, gift certificates are handled in-house; the information is all stored in a database, so there is quite a bit of variation here.

4.6.1. Overridable and Overrides

An existing behavior in a base class can be completely redefined by overriding it in the derived class, but only if the writer of the base class has made it permissible to do so. For a method to be overridden, it must be declared by using the Overridable modifier. Naturally, this suggests some foresight on the part of the class designer. If the method is not marked as overridable, one of two things is happening: the person who coded the class does not want the method to be overridden, or he or she was not thinking ahead of the game. In the latter case, there is a loophole of sorts (see "Shadowing" at the end of this chapter) in the language that allows circumvention of this grievous situation. But for now, assume that ...

Get Object-Oriented Programming with Visual Basic .NET now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.