Interface

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Can anyone please explain to me why some classes should be
implemented as part of an interface and others not? I know
what an interface is, but I'm still not quite sure about
why it should be used. Thanks a lot for all your answers.
 
Greets,

Actually, it's the class which implements the interface. Interfaces are
basically like a "contract" which is adhered to by the class that derives
from and implements the interface. A good example of where an interface
would be useful is, say, for an application which uses add-in modules.
Although the add-in modules may be functionally different in how they work,
they can be accessed by the application which loads them through their
interfaces. The host application only knows that the add-in had implemented
the interface and it uses that interface to communicate with the add-in
module. Because the interface is a standard contract, the host application
can easily work with a set of homogeneous add-in modules that provide their
implementation. As an example of what types the interface may specify,
perhaps each add-in has a name, description and major/minor version
properties. Also, each one may have a Startup(), Process() and Shutdown()
method which is common to all add-in modules. By creating an interface with
these properties and methods, a class can derive from that interface,
provide the necessary code and be considered an add-in module which works
with the host application.

Regards,

Joe
 
Back
Top