Sandeep asks:

> How do interfaces help i n multiple inheritence? If
> I have a ClassA and ClassB then if I want to inherit ClassC from
> ClassA its simple. But if I want to inherit from ClassA and ClassB
> then using interface I have to implement all the functions in ClassB
> again in ClassC, so how does it makes life simple?

The main use for multiple inheritance is defining an object that has the
nature of two other classes. And the intention is not to aggregate
functionality so much as to have a new object that is can be treated as
either of the two bases classes.

When you express things this way you see that the use of the base classes in
this case is highly misleading, as you are not defining functionality so
much as the "interface" by which you want to talk to an object. The base
classes exist simply to provide virtual abstract methods that descendants
will have in common.

So instead of using artificial base classes to define common interfaces, you
explicitly define the interface(s) that you to have available, and leave it
up to the objects to implement the interface(s) if they need to. Then
objects of several different hierarchies can all be treated transparently in
a certain context.

The above does not imply that you can use inheritance to provide base
objects classes that all implement a certain interface, not does it prevent
the interfaces being delegated by objects to other objects that they
aggregate.

So one method of avoiding the problems that you mention above is to have
both ClassB and ClassC use an instantiation of a separate object ClassD to
implement a certain behaviour, and bother provide an interface that
delegates the interface down to that class. Then you have both code sharing,
inheritance and interfaces all working together to provide the actual object
functionality you want to express.

Cheers, Max.


---------------------------------------------------------------------------
    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz
To UnSub, send email to: [EMAIL PROTECTED] 
with body of "unsubscribe delphi"

Reply via email to