Re: Interfaces...am i missing the point?
- From: "Maarten Wiltink" <maarten@xxxxxxxxxxxxxxxxxx>
- Date: Mon, 30 May 2005 15:34:13 +0200
"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
.
- References:
- Interfaces...am i missing the point?
- From: dvddude
- Interfaces...am i missing the point?
- Prev by Date: Re: Using ZLib
- Next by Date: Re: COM interfaces
- Previous by thread: Interfaces...am i missing the point?
- Next by thread: Re: Interfaces...am i missing the point?
- Index(es):
Relevant Pages
|
|