>> 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.


Actually it does... With TGUIDs on both interfaces I can now use

(Lst.Items[0] as IList).GetStrings(Listbox1.Items);

Works rather nicely actually and has confirmed that I will now be migrating
heavily to interfaces as time allows to better implement aggregation.

>> 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.


It turns out that interfaces are completely castable but but the cast must be
a procedural cast not explicit and the casting interface must declare a GUID.

IE
IList(Lst.Items[0])  ** BAD **
(Lst.Items[0] as IList) ** Works **

>>  (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.


Given the delegation facilities to implement aggregation of object classes
it seems that multiple inheritance is almost entirely implemented.

>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!


My Spades are now also Forks... And while you were right in this instance
inheritance was more logical in many cases delegation will enable me to implement
listability on my objects with a delegation property, a constructor and a destructor.
Nice... :)

>>  (B) how do you generate a unique GUID
>In Delphi IDE, CTRL-SHIFT-G.


Do these number shave to be unique across machines. IE if I use the application
on another machine with the GUID already used will things get messy...

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


Not a chance ;)  Thanx for the GUID generation tip... I looked up TGUID and GUID
along with Interface but must've overlooked it if the reference was there..

--
Aaron Scott-Boddendijk
Jump Productions
(07) 838-3371 Voice
(07) 838-3372 Fax

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

Reply via email to