|
June 30, 2002 Implementing a Polymorphic Utility Tips: June 2002
Yehuda Shiran, Ph.D.
|
|
Polymorphism is easy to demonstrate
using utility functions. Utility functions are like methods of the main program,
or of the global object as it is sometimes called in other languages. You
define a utility function in the main program section, before, after, or in between
the class definitions. Our utility function, CopyMe(),
accepts an object of type Object,
and returns a copy of it by using the Copy()
method. Here is the utility function:
The Copy() method is defined in the interface ICopyObj:
The following two classes, CopyInt and CopyDouble, implement this interface for integer and double values, respectively:
To learn more about JScript .NET, go to Column 111, JScript .NET, Part V: Polymorphism.
People who read this tip also read these tips: Look for similar tips by subject: |