Hi,

> I have a question regarding the use of interfaces.
> 
> if I have 2 interfaces
> 
> IListtem = interface
>   ...
> end;
> 
> IList = interface
>   ...
>   property Items[Index :Integer]:IListItem read GetItems; default;
>   procedure GetStrings(Strings :TStrings);
> end;
> 
> and I declare a class
> 
> TListableList = class(TInterfacedObject,IList,IListItem)
> end;
> 
> This should allow lists of lists.

Well, no. It means you have a class which can act as an IList, or an
IListItem.

> However when I retrieve the first item from the
> top level list I recieve an interface of type IListItem 

This is because the Items property returns an IListItem. The fact that
the object returned also implements IList isn't relevent. You can't
really 'cast' interfaces.

>  (A) am I going about this right

I think you're hoping that interfaces are a way of implementing
multiple inheritance (and they are, kinda), but what you're attempting
doesn't suit interfaces.

Interfaces are a great way of ensuring that a spade is a spade is a spade,
and of isolating code from implementation dependancies. Your code is saying
that an IListItem is sometimes an IList, which doesn't fit!

>  (B) how do you generate a unique GUID

In Delphi IDE, CTRL-SHIFT-G.

>  (C) Can you then use AS to legally cast between 2 interfaces. (all help examples
>       show casting between a class and an interface).

I don't think so.

> Also should I be implementing the IListItem interface as a base class and use
> delegation to implement the behaviour or is this not the preferred methodology.

For this example, I'm sure that'd be fine (except you'd be using inheritance
rather than delegation, right?)

That said, I've come to really *like* interfaces, so don't abandon them 
forever just yet.

Cheers,
Kerry S
---------------------------------------------------------------------------
    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz

Reply via email to