BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Interface and inheritance problem

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi OO design
View previous topic :: View next topic  
Author Message
R. Vermeij
Guest





PostPosted: Mon Nov 22, 2004 2:17 pm    Post subject: Interface and inheritance problem Reply with quote




I have this hierarchy:

IBaseConfigurationFile = interface
IBaseNamedFile = interface(IBaseConfigurationFile)
IMachineTypeFile = interface(IBaseNamedFile)
(all three interfaces have a GUID)

TBaseConfigurationFile = class(TInterfacedObject, IBaseConfigurationFile)
TBaseNamedFile = class(TBaseConfigurationFile)
TMachineTypeFile = class(TBaseNamedFile, IMachineTypeFile)

In a method I pass: (AFile: IBaseConfigurationFile)

Why does:
Supports(AFile, IBaseNamedFile, BaseNamedFile)
return False?
Supports(AFile, IMachineTypeFile, MachineTypeFile)
return True?
Supports(AFile, IBaseConfigurationFile, BaseConfigurationFile)
return True?

(I am quite new to interfaces, so I guess I misunderstand something...)
Back to top
Angel
Guest





PostPosted: Mon Nov 22, 2004 5:57 pm    Post subject: Re: Interface and inheritance problem Reply with quote



Delphi object model required that in class declaration you have to mention
all interfaces this
class implements even if this interface has been inherited from other
interface than this class implements:

TMachineTypeFile = class(TBaseNamedFile, IMachineTypeFile,
IBaseConfigurationFile)

Regards
Angel





"R. Vermeij" <rSv (AT) veroPmaAMtic (DOT) nl> wrote

Quote:

I have this hierarchy:

IBaseConfigurationFile = interface
IBaseNamedFile = interface(IBaseConfigurationFile)
IMachineTypeFile = interface(IBaseNamedFile)
(all three interfaces have a GUID)

TBaseConfigurationFile = class(TInterfacedObject, IBaseConfigurationFile)
TBaseNamedFile = class(TBaseConfigurationFile)
TMachineTypeFile = class(TBaseNamedFile, IMachineTypeFile)

In a method I pass: (AFile: IBaseConfigurationFile)

Why does:
Supports(AFile, IBaseNamedFile, BaseNamedFile)
return False?
Supports(AFile, IMachineTypeFile, MachineTypeFile)
return True?
Supports(AFile, IBaseConfigurationFile, BaseConfigurationFile)
return True?

(I am quite new to interfaces, so I guess I misunderstand something...)



Back to top
Joanna Carter (TeamB)
Guest





PostPosted: Mon Nov 22, 2004 6:52 pm    Post subject: Re: Interface and inheritance problem Reply with quote



"Angel" <afilev (AT) pcreducator (DOT) com> a écrit dans le message de news:
41a22870$1 (AT) newsgroups (DOT) borland.com...

Quote:
TMachineTypeFile = class(TBaseNamedFile, IMachineTypeFile,
IBaseConfigurationFile)


or

TBaseNamedFile = class(TBaseConfigurationFile, IMachineTypeFile)

:-)

Joanna

--
Joanna Carter (TeamB)

Consultant Software Engineer
TeamBUG support for UK-BUG
TeamMM support for ModelMaker



Back to top
Joanna Carter (TeamB)
Guest





PostPosted: Mon Nov 22, 2004 8:26 pm    Post subject: Re: Interface and inheritance problem Reply with quote

"Joanna Carter (TeamB)" <joannac (AT) btinternetxx (DOT) com> a écrit dans le message
de news: 41a23587$1 (AT) newsgroups (DOT) borland.com...

Quote:
TBaseNamedFile = class(TBaseConfigurationFile, IMachineTypeFile)

Sorry, should have been :

Quote:
TBaseNamedFile = class(TBaseConfigurationFile, IBaseNamedFile)

Joanna

--
Joanna Carter (TeamB)

Consultant Software Engineer
TeamBUG support for UK-BUG
TeamMM support for ModelMaker



Back to top
R. Vermeij
Guest





PostPosted: Tue Nov 23, 2004 6:17 am    Post subject: Re: Interface and inheritance problem Reply with quote


I suspected that already :-(

But why then does this return True?

Supports(AFile, IBaseConfigurationFile, BaseConfigurationFile)
where:
AFile: IBaseConfigurationFile
TMachineTypeFile = class(TBaseNamedFile, IMachineTypeFile)
AFile is filled with a TMachineTypeFile

Is this because the interface variable itself is of type IBaseConfigurationFile?

Or should my declaration be:
TMachineTypeFile = class(TBaseNamedFile, IBaseConfigurationFile, IBaseNamedFile, IMachineTypeFile)

(In other words, what is the best way to do this?)

Ruud
Back to top
R. Vermeij
Guest





PostPosted: Tue Nov 23, 2004 6:33 am    Post subject: Re: Interface and inheritance problem Reply with quote


o-: **** AHA-ERLEBNISS **** :-o

Now I see my error.
I forgot to implement IBaseNamedFile on TBaseNamedFile!

Quote:
TBaseNamedFile = class(TBaseConfigurationFile)

should have been:

TBaseNamedFile = class(TBaseConfigurationFile, IBaseNamedFile)

Well, many thanks to Angel and Joanna!

Ruud

Back to top
Roman Kaßebaum
Guest





PostPosted: Tue Nov 23, 2004 8:25 am    Post subject: Re: Interface and inheritance problem Reply with quote

R. Vermeij schrieb:
Quote:
I have this hierarchy:

IBaseConfigurationFile = interface
IBaseNamedFile = interface(IBaseConfigurationFile)
IMachineTypeFile = interface(IBaseNamedFile)
(all three interfaces have a GUID)

Interfaces should habe only few methods, thats's why in many cases it
would be better not to use inheritance in interfaces.
The delphi-objects, that provide the interfaces, should use inheritance.

--
Roman

Back to top
Joanna Carter (TeamB)
Guest





PostPosted: Tue Nov 23, 2004 9:37 am    Post subject: Re: Interface and inheritance problem Reply with quote

"Roman Kaßebaum" <roman.kassebaumnospam (AT) kdv-dt (DOT) de> a écrit dans le message
de news: [email]41a2f3e2 (AT) newsgroups (DOT) borland.com[/email]...

Quote:
Interfaces should habe only few methods, thats's why in many cases it
would be better not to use inheritance in interfaces.
The delphi-objects, that provide the interfaces, should use inheritance.

If I may explain further...

When designing Interfaces, you are declaring behaviours that may or may not
inherit from each other.

e.g. You could do something like this :

IConfiguration
IName
IMachine

TConfigurationFile = class(TInterfacedObject, IConfiguration)
TNamedFile = class(TInterfacedObject, IConfiguration, IName)
TMachineFile = class(TInterfacedObject, IConfiguration, IName, IMachine)

OTOH, you could also implement them like this :

TConfigurationFile = class(TInterfacedObject, IConfiguration)
TNamedFile = class(TConfigurationFile, IName)
TMachineFile = class(TNamedFile, IMachine)

or even possibly

TMachineFile = class(TConfigurationFile, IName, IMachine)

I am not saying that you should never inherit interfaces, just to check
whether one interface is really an extension of the behaviour of another;
and regard the inheritance of interfaces differently to the inheritance of
classes.

Joanna

--
Joanna Carter (TeamB)

Consultant Software Engineer
TeamBUG support for UK-BUG
TeamMM support for ModelMaker



Back to top
Roman Kaßebaum
Guest





PostPosted: Tue Nov 23, 2004 9:43 am    Post subject: Re: Interface and inheritance problem Reply with quote

Joanna Carter (TeamB) schrieb:
Quote:
I am not saying that you should never inherit interfaces, just to check
whether one interface is really an extension of the behaviour of another;
and regard the inheritance of interfaces differently to the inheritance of
classes.

Absolutely correct, that's I wanted to say.

--
Roman


Back to top
R. Vermeij
Guest





PostPosted: Tue Nov 23, 2004 10:24 am    Post subject: Re: Interface and inheritance problem Reply with quote


Quote:
Interfaces should habe only few methods, thats's why in many cases it
would be better not to use inheritance in interfaces.
The delphi-objects, that provide the interfaces, should use inheritance.

The reason I use interfaces here, is the garbage collection functionality that comes with the reference counting.

It is convenient for me to have the class inheritance tree be parallel to the interface (inheritance) tree.

But I understand what you are saying (and I'm learning)!

Ruud

Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi OO design All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.