Groups > Borland > Delphi Object Oriented design > Re: Beginers question about Interfaces




Re: Beginers question about Interfaces

Re: Beginers question about Interfaces
Fri, 4 Jan 2008 17:00:12 -0600
"Anderson Farias" wrote
> >>    function: ImplementingObject: TComponent;
> >>   // but this really is a bad idea in most cases
>
> Could you tell me why??

A major point of interfaces is to abstract functionality from implementing
class, so that, for example, IPrintable could be implemented by any number
of actual classes that might have no ancestry in common (higher than
TObject).

Including the Implementing class (TComponent as above or whatever) in the
interface defeats this flexibility--now the implementing class has to be of
that declared type. If the interface really has to be implemented by one
specific class, then you generally simplify the code by just passing the
class and not using interfaces at all.

And of course, as Gerrit said, if you need to be able to access the
implementing object, then that's a pretty strong indication that the
interface isn't designed correctly. Anything that the interface legitimately
needs to do should be available though the interface itself.

bobD


Post Reply
Re: Beginers question about Interfaces
Fri, 4 Jan 2008 19:46:03 -0300
Hi,

>>    function: ImplementingObject: TComponent;
>>   // but this really is a bad idea in most cases

Could you tell me why??


Thanks
regards,
Anderson 

Post Reply
Re: Beginers question about Interfaces
Sat, 5 Jan 2008 00:50:12 -0300
Thanks for the explanation Bob, very apreciated!


Regards,
Anderson

"Bob Dawson" wrote
>
> A major point of interfaces is to abstract functionality from implementing
> class, so that, for example, IPrintable could be implemented by any number
> of actual classes that might have no ancestry in common (higher than
> TObject).
> (...) 

Post Reply
Re: Beginers question about Interfaces
6 Jan 2008 02:54:18 -0700
Bob Dawson wrote:

> And of course, as Gerrit said, if you need to be able to access the
> implementing object, then that's a pretty strong indication that the
> interface isn't designed correctly. Anything that the interface
> legitimately needs to do should be available though the interface
> itself.

I Agree with you both here, but somethimes you need to interact with
VCL like hook some event, so you need to pass the implementing object
as parameter, but for me, is the only case I needed until now.

-- 

[]s


Post Reply
about | contact