A class has a unique fingerprint which is defined by it's namespace, name,
method and property signatures. This signature makes the class
distinguishable from all other classes.
This can be an advantage or a disadvantage. For example, if you want to
create an object that knows how to draw itself you might do so by creating a
base-class with a DrawMe method. Now, all classes derived from this base
will have a DrawMe method and can override that somehow to draw their
different appearences. The disadvantage to this is that the base class with
the DrawMe method must be in the inheritance chain in order for the system
to work. You could not create some other arbitrary class with a method
called DrawMe and use it in your toolbox of objects because it wouldn't be
derived from the expected base class.
Using an interface however, you can create a system that will "morph" the
signature of any class so that you can add a specific method or property to
it and not have to be concerned about it's derivation. The interface
provides this "contract" which simply says that the class which implements
the interface agrees to behave in a certain manner regardless of it's true
class or method signatures. Effectively, the interface can be thought of as
the duplicate key that can be passed around so that anyone can use a
particular car. Anyone with the key can drive the car, anyone with the
interface can operate the functionality provided in the interface contract.
In this example, an interface called IDrawable might have just a single
method called DrawMe. This can be implemented by any class but whoever gets
hold of hose classes will know that the thing draws itself by the fact that
it implements IDrawable. If you can cast an object to IDrawable, it will
obey the rules of the contract.
Hope this helps.
--
Bob Powell [MVP]
Visual C#, System.Drawing
Ramuseco Limited .NET consulting
http://www.ramuseco.com
Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm
Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm
All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
"dj" <dj@discussions.microsoft.com> wrote in message
news:31**********************************@microsof t.com...
I know seasoned OOP-savvy developers will roll their eyes at this one, but
can anyone provide a clear explanation as to *why* one would need to use
an
Interface in a VB.NET application?
Every book and article I seem to run across jumps right into "and here's
how
Interfaces are implemented..." followed by a block of meaningless (to me)
code without explaining why this is being used in the first place. e.g.
Why
not use a Class object?
TIA,
dj