Re: Interfaces...am i missing the point?
- From: "Maarten Wiltink" <maarten@xxxxxxxxxxxxxxxxxx>
- Date: Tue, 31 May 2005 10:31:20 +0200
"Rob Kennedy" <me3@xxxxxxxxxxx> wrote in message
news:3g1b1fFa4lr1U1@xxxxxxxxxxxxxxxxx
[...]
> Furthermore, any language that understands interfaces can use them the
> same way. You can't pass a TObject to a C++ program and expect it to
> do anything -- and you definitely can't pass a C++ object to Delphi
> and get anything useful from it -- but you can pass an IMyInterface
> reference to both those languages and they'll know exactly what to do.
This is true for _COM-compatible_ interface implementations. Delphi
is, by design, but other designs are possible. In Java it's probably
optional.
[...]
> XML libraries are a good example. Borland declares lots of XML
> interfaces, mainly based on the W3C DOM specifications. Borland then
> provides several other units that all contain objects implementing
> those interfaces. One implementation is based on Microsoft's XML
> library. Another implementation is done entirely in Delphi code.
> They're two very different implementations, and it would probably
> have been difficult to adapt them both to the same object hierarchy
> because there would be very little in the way of implementation code
> that they could share. The only things they could end up sharing
> would be a set of abstract methods, and a class with all abstract
> methods is essentially an interface. When using the XML interfaces,
> the library-specific code is very limited. All you do is call the
> single library-specific function to create an instance of the
> IDomDocument interface, and from there you just call that interface's
> methods. The code that _uses_ the XML objects doesn't need to know
> anything about which implementation is in use.
Another example is TStrings. It's _almost_ a purely abstract class,
and different implementations exist. TStringList is the visible one,
it implements all the abstract functionality declared by TStrings in
a straightforward and self-contained way. It also adds a few small
things, which unfortunately muddies the picture a bit.
There is also at least one other implementation, which is used (only) by
a number of controls that contain lines of text, possibly decorated with
pointers: memoes, listboxes, comboboxes. These implementations are aware
of the control they live in and know exactly how to have everything
required done by the control itself. These controls already implement
all the behaviour required by the TStrings contract, but differently.
So this other TStrings-derived object implements all the abstract methods
by sending Windows messages to its containing control, and is used to
make the existing functionality of the control available to Delphi
programmers in a different form, as described by the TStrings class.
The object is accessible through a property (Lines or Items). Since
TStrings is a class and not an interface, the mechanism for getting
an interface reference from an object reference doesn't apply.
Groetjes,
Maarten Wiltink
.
- References:
- Interfaces...am i missing the point?
- From: dvddude
- Re: Interfaces...am i missing the point?
- From: Rob Kennedy
- Interfaces...am i missing the point?
- Prev by Date: Re: BNF notation for Delphi Grammar
- Next by Date: String from res file
- Previous by thread: Re: Interfaces...am i missing the point?
- Next by thread: Hard Core Threading (TMREWS on Linux)
- Index(es):
Relevant Pages
|
|