Can i do that?
type
IIntf3 = interface(IIntf11, IIntf2)
....
end;Thanks in advance.

Mailing lists / fpc-pascal / 2011-04
12 messages · 6 people · –
Reply by email Subscribe to this list Your subscription
Read-only archive. Use j and k to move between messages.
Can i do that?
type
IIntf3 = interface(IIntf11, IIntf2)
....
end;Thanks in advance.
Err... yes? Why don't you just try?
leledumbo wroteErr... yes? Why don't you just try?
I tried before my post and failed, the idea is there any way enable it (like directive to add it), or it is implmented in the next versions of FPC, or only the answer is No :)
Regards
Can i do that? type IIntf3 = interface(IIntf11, IIntf2) .... end; Thanks in advance.…
Zaher Dirkey kirjoitti keskiviikko, 6. huhtikuuta 2011 19:37:04:
No but you can do:
type
MyClass = class(IIntf11, IIntf2)....
end;Juha
Can i do that? type IIntf3 = interface(IIntf11, IIntf2) .... end; Thanks in advance.…
For Corba interfaces, yes. Not for COM interfaces. http://www.freepascal.org/docs-html/ref/refse39.html
-Flávio
2011/4/7 Flávio Etrusco
I added {$INTERFACES CORBA} but same error ~Fatal: Syntax error, ")" expected but "," found~ in the line ~IIntf3 = interface(IIntf11, IIntf2)~
The whole idea of interfaces is to avoid multiple inheritance.
So you can never inherit from more than one interface.
Also not in CORBA interfaces. The mentioned page of the manual nowhere states that this is possible. It just says that for CORBA interfaces, the interface does not descend from IUnknown.
Michael.
My bad, I just answered based on the Delphi implementation. I sent the link just for the sake of "reference".
Best regards,
Flávio
On Fri, 8 Apr 2011,michael.vancanneyt worte:
The whole idea of interfaces is to avoid multiple inheritance.
Hm. I don't believe that.
One of the major points of interfaces is indeed to avoid the problems of multiple class inheritance (diamond problems - i.e. problems caused by conflicting implementations of a method in different ancestor classes).
But Interfaces themselves don't have an implementation, so those diamond problems simply don't exist for them.
I don't think there's a good reason against multiple interface inheritance.
Not having multiple interface inheritance complicated certain situations for myself.. forcing me to put runtime interface-casts into my code that a compiler with multiple interface inheritance could have Andreas
Of course they do. If they inherit from 2 interfaces that have the same method with a different signature, you have a problem.
InterfaceA = Interface
Function IsValid : Integer;
end;
InterfaceB = Interface
Function IsValid : String;
end;How to define :
InterfaceC = Interface(InterfaceA,InterfaceB)
Michael.
On Tue Apr 12, michael.vancanneyt worte:
Good point.
Well, I don't see a diamond here as such a serious problem as it is for multiple class inheritance. (where eventually trying to override the conflicting methods in descendant classes will bite...)
C# handles multiple interface inheritance quite well, so I'm quite confident that it's possible to get it done right.
As far as I've seen the "diamond problem for interface inheritance" there just means that it's not directly possible to call an ambigous method directly from InterfaceC without first casting to Interface A or B - and that sounds rational to me. What's important is that you can get from C to A and B without a blind cast and then call the method you like.
How to define : InterfaceC = Interface(InterfaceA,InterfaceB)
Let's give it a try:
Interface A and B are sets of pointers to Methods, InterfaceC then simply is the union of those sets. (As a pure contract InterfaceC itself doesn't really have to contain non-ambiguous signatures)
It's no problem for a class to implement Interface A and B at the same time anyway...
TTest = class(TObject, InterfaceA, InterfaceB)
function InterfaceA.IsValid = IsValid_A;
function InterfaceB.IsValid = IsValid_B;
function IsValid_A: Integer;
function IsValid_B: String;
end;All ambiguities regarding implementation can be resolved by the implementing class. It just has to map all the pointers to (non-conflicting) method implementations.
..
Finally I'd like to mention one usecases for interface inheritance I'd like to have:
1) Splitting a big IDataInterface into smaller ones, like: IDataInterface = Interface(IInitMethods, IReadMethods, IEditMethods, ...)
This would allow me to pass an IDataInterface into Factories, Loggers, etc. without passing too many methods and without ugly runtime casts or artificial single-inheritance chains...
2) Containers. Without multiple inheritance it's a pain to get some things like:
IMyContainer = Interface(ISortableContainer, IVectorList, IEditableList, ...)
Practically for me not having multiple interface inheritance sometimes leads to:
a) artificial (single) inheritance chains
b) blind runtime casts instead of casts to a known parent c) having to pass parameters that are bigger than necessary (IQuery instead of IReadOnlyQuery)
All in all I'd really like to have multiple interface inheritance...
Of course they do. If they inherit from 2 interfaces that have the same method with a…
I think, compile raise error duplicated methods, Same if inherit from one and add a method already exists in parent interface.
Regards