IcompleteInterface = interface(IsubInterface1, IsubInterface2, IsubInterface3) not possible ?



Hi,

I am evaluating if interfaces are the right solution for my problem and now
I have a basic question:

(Interfaces could be interesting since they have automatic referencing
counting and could be used to automatically clean up or recycle objects as
soon as they are no longer referenced etc... thereby solving the problem of
how to get more performance by preventing copies and preventing extra code
for cleaning up stuff and recycling etc. )

It *is* possible that a class can inherit from multiple interfaces like so:

TcompleteClass = class( TinterfacedObject, IsubInterface1, IsubInterface2,
IsubInterface3 )

For referencing counting to work properly variables have to be of an
interface type.

So creating this object would require something like this:

var
SubInterface1 : IsubInterface1;
begin
SubInterface1 := TcompleteClass.Create;
end;

Destructors should never be called since this is now done automatically.
Calling the destructor will raise an exception by the TinterfacedObject
which sees that the reference count is higher than zero so it does not allow
the destruction because something is still referencing it etc.

I now have a new problem. How to reference the "full/complete" object. This
seems impossible ?

Since now I have to have 3 different variables to access the complete object
for example:

var
SubInterface1 : IsubInterface1;
SubInterface2 : IsubInterface2;
SubInterface3 : IsubInterface3;

SubInterface1 := TcompleteClass.Create;
SubInterface2 := ???;
SubInterface3 := ???;

That's the first problem.

I would like to solve this problem simply by creating a "complete interface"
like so:

IcompleteInterface = interface(IsubInterface1, IsubInterface2,
IsubInterface3)
function Tata : string;
end;

And then simply define/declare the class as follows:

TcompleteClass = class( TinterfacedObject, IcompleteInterface)

And then simply access the object as follows:

var
CompleteInterface : ICompleteInterface;

CompleteInterace := TcompleteClass.Create;
etc...

However delphi does not allow me to define

IcompleteInterface = interface(IsubInterface1, IsubInterface2,
IsubInterface3)

????

Why is that ?

Sigh.

How am I suppose to work with/access objects which have multiple interfaces
??? without messing up the reference counting etc...

One solution might be to use inheritance like this:

A = Interface
B = Interface(A)
C = Interface(B)
CompleteInterface = Interface(C)

But this more or less defeats the whole purpose of interfaces ?

Having completely seperate interfaces which can all be inherited via
multiple inheritance seems kinda nice ;)

Bye,
Skybuck.


.



Relevant Pages

  • snmp requests CORRECTED!
    ... After referencing the MIB, I can follow the path to interfaces, but I get ... lost at 0 as there is no 0 on the MIB map. ...
    (perl.beginners)
  • snmp requests
    ... After referencing the MIB, I can follow the path to interfaces, but I get ... lost at 0 as there is no 0 on the MIB map. ...
    (perl.beginners)
  • Re: The Language I want
    ... inheritance of interfaces from concrete types. ... Generics is a huge mess. ... Templates or hygenic macros are not generics! ...
    (comp.lang.misc)
  • Re: The Language I want
    ... inheritance of interfaces from concrete types. ... It has nothing to do with inheritance. ... dispatch in some parameter, you would declare it on the class rather than ...   f: T x P ...
    (comp.lang.misc)
  • Re: The Language I want
    ... inheritance of interfaces from concrete types. ... I disagree this is a meta language and an object language, ... Multiple dispatch. ...
    (comp.lang.misc)