Re: Interfaces...am i missing the point?



"dvddude" <dvddude@xxxxxxxxxxxx> wrote in message
news:_XDme.986$hT6.490@xxxxxxxxxxxxxxxxxxxxxxx

> OK i have been reading about interfaces
>
> I have learned that when i include an interface as part of an object...
>
> TMyObject = class(Tobject, IMyInterface)
>
> I then have to implement all the functions/procedures defined in the
> interface, inside my object??
>
> So why have to interface in the first place, why not just create all
> the function as methods of the object as i'll have to do that anyways.

Sometimes you can't. I once wanted to add the same behaviour to a
number of different controls, but of course at their common root that
behaviour wasn't yet known. Interfaces let you add a virtual root, so
to speak.

Assume for the moment that I dealt with panels and editboxes, and that
I wanted to add an Init() method to both. The common root of TPanel and
TEdit is TControl or something, and Init() would be in TmwPanel and
TmwEdit, not in TControl. So I couldn't write "CurrentObject.Init()"
because to fit both a TPanel and a TEdit, CurrentObject would be a
TControl. If TmwPanel and TmwEdit both implement ImwInit, CurrentObject
could be an interface reference and I could call Init() on it.

This is only an example. If you do have control over the base class of
your objects, you may still not want to burden the base class with
methods it shouldn't need to know about.

Groetjes,
Maarten Wiltink


.



Relevant Pages

  • Re: Duplicate definition on Interface declaration
    ... Interface class. ... Init() method perhaps? ... There are no conditional compile arguments named "Init". ... definition error when I try to display some forms and/or controls in the IDE ...
    (microsoft.public.vb.general.discussion)
  • Re: hiding an interface (VB6)
    ... > to even be able to get to the write members. ... > ensures that it is only called once, and where the Init() function is the ... Then, the object recipient could ... The recipients use refs to one interface, ...
    (microsoft.public.vb.general.discussion)
  • Re: Duplicate definition on Interface declaration
    ... start the application in the IDE, it does the JIT compile and then ... Interface class. ... I've searched the Microsoft site, the MSDN site, ... Init() method perhaps? ...
    (microsoft.public.vb.general.discussion)
  • Class question
    ... is exactly the same code as I had before in init. ... function retuns me a placeholder. ... tabed interface? ... Namespace intranet ...
    (microsoft.public.dotnet.framework.aspnet)