IcompleteInterface = interface(IsubInterface1, IsubInterface2, IsubInterface3) not possible ?
- From: "Skybuck Flying" <nospam@xxxxxxxxxxx>
- Date: Wed, 28 Sep 2005 11:21:18 +0200
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.
.
- Prev by Date: Re: reading a opened file
- Next by Date: FFT class or routines
- Previous by thread: Pascal Look - help you understand your pascal unit file
- Next by thread: Re: IcompleteInterface = interface(IsubInterface1, IsubInterface2, IsubInterface3) not possible ?
- Index(es):
Relevant Pages
|