
28
|
Chapter 3: Introduction to Object-Oriented Programming
This is the Title of the Book, eMatter Edition
Copyright © 2006 O’Reilly & Associates, Inc. All rights reserved.
Dog-specific versions of those members can be added to the Dog class. Any Dog
object that calls these methods will use the Dog-specific versions; any general Pet
object will use the default Pet-specific versions. If your code is currently treating a
Dog object as a more generic Pet object, it will still use the Dog-specific versions,
since the object is still a Dog.
Sound confusing? Welcome to polymorphism. Fortunately, the Visual Basic
compiler figures out all of these relationships for you; you just need to write your
code to enable the class-specific actions you require.
Overloading
Sometimes it is useful to have more than one way of performing the same action
in a single class. For instance, if your Dog class has a TakeForWalk action, you
might require several ways of taking this action to mimic real-world actions. For
instance, you might want to call TakeForWalk with a time duration (“30
minutes”) for a generic time-based walk, or call it with instructions for a specific
path-based exercise plan. You would need one version of this action that takes a
number (time-based) and one that takes a path plan (path-based), perhaps sent as
a string.
When a class includes multiple versions of the same member that differ by their
argument ...