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



"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


.



Relevant Pages

  • Re: Discovering variable types...
    ... >> TStringList would be the reference example. ... > a reference implementation for TStrings. ... >> that abstract datastructure is NOT inheritly OOP. ... But Delphi includes syntax for declaring the interface, ...
    (comp.lang.pascal.delphi.misc)
  • Re: Discovering variable types...
    ... >> usually just TStrings) the way you want it to. ... If that was the case, there would be a IStringList interface, and ... in a recent Delphi version. ... > that abstract datastructure is NOT inheritly OOP. ...
    (comp.lang.pascal.delphi.misc)
  • Re: Discovering variable types...
    ... >> It is slow because it is a single array of pointers internally. ... > just TStrings) the way you want it to. ... but that is because the OOP overhead mattered for the TList ... > Classes are a marvellous way to fix an interface and implement it a hundred ...
    (comp.lang.pascal.delphi.misc)
  • Re: Accessing value of a Variable in parent from custom control
    ... get some kind of information from the parent form in which the control ... If Form1 implements an interface, it means that you must provide the ... Implements iUsesMyControl ... Public Property FormString() As String Implements ...
    (microsoft.public.dotnet.framework)
  • Re: Accessing value of a Variable in parent from custom control
    ... problem is that the control is not awair of either the iUsesMycontrol ... get some kind of information from the parent form in which the control ... If Form1 implements an interface, it means that you must provide the ...
    (microsoft.public.dotnet.framework)