Oh boy... I remember being where you are right now. It took forever for
me to 'get' the concept. Perhaps this will help:
All cars have a dashboard, right? And in that dashboard you always see
a speedometer and a gas guage, right? Ok... Those requirements are the
dashboard INTERFACE.
Some cars measure speed by running a cable from the transmission. Some
cars measure speed by running a cable from the wheel. Some cars
(perhaps) measure speed by a little propeller on the roof.
Your dashboard interface does not care HOW the speed is measured, as
long as it receives an value from the measuring device that you can
display on your speedometer. Same thing for the gas guage.
What your dashboard interface WON'T allow is a situation where you don't
have a speedometer and a gas guage. Your dashboard may have many other
features like a tachometer and a odometer, but in order to qualify as
one of your dashboards, it must have both a speedometer and a gas guage.
----
Ok.. That's the concept. The real question you ask, which is what
stumpped me for months, is WHY and WHEN would you use it?
Any time you are writing a class where you REQUIRE a minimum set
properties and methods to be present, you create an interface.
I use interfaces with a bunch of UserControls I have created. All of my
controls do different things and look different, but they all have a
property called IsNull. How each control determines if it is null
varies from one to the next, but in my main program, where I use many of
these UserControls I can simply call the IsNull property and get a
boolean value returned. All of my controls implement this interface so
I am guaranteed that the IsNull property will be present.
Hope this helps... It took several explanations and months fo playing
before it really clicked for me, so don't dispair... you'll get it
eventually!
--Zorpie
*** Sent via Developersdex
http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!