Reuse code when interfaces implements the same method 
Author Message
 Reuse code when interfaces implements the same method

Hello!

I am currently writing some ActiveX dll:s which implements different
interfaces.
Here is the problem:

I have two interfaces.
Interface A support method :  getCustomer and setCustomer
Interface B supports only  method : getCustomer

When I then writes a COM objects which implements both of
these interfaces. The method getCustomer needs to be written
two times.  It will look something like :
:
Private Function A_getCustomer()
    Do some thing
End Function
Private Function  B_getCustomer()
    Do the same thing as the function above
End Function
:

Is there a way to let both interfaces use the same
method?

By the way is there anybody who now some good book covering IDL programming?

Salute
/David



Tue, 25 Jul 2000 03:00:00 GMT  
 Reuse code when interfaces implements the same method

Quote:
>Is there a way to let both interfaces use the same
>method?

I don't think there is (in VB at least).  You could code a private
GetCustomer and routes each of the interface methods to it.

Quote:
>By the way is there anybody who now some good book covering IDL

programming?

Assuming you are talking about using interfaces in ActiveX components
(specifically with VB):

"Java Design" ISBN 0-13-271149-4

This book has some good stuff on designing with interfaces.  A helpful book
for anything (not just Java).

"Professional DCOM Programming" ISBN 1-861000-60-X

A C++ book but helped me learn a lot more about COM/DCOM and interfaces.

"{*filter*} Visual Basic" ISBN 1-57231-422-2

Not exclusively about interfaces but a dense book with some good material on
interfaces and polymorphism.

"Com and Dcom : Microsoft's Vision for Distributed Objects"
ISBN 047119381X

Uses Java for the middle tier examples but some good material on interface
design.

"Doing Objects in Micorsoft Visual Basic 5.0"
ISBN 1-562-76-444-6

A clear, straight-forward chapter on interfaces.

Hope this helps

Quote:

>Salute
>/David



Tue, 25 Jul 2000 03:00:00 GMT  
 Reuse code when interfaces implements the same method

In my opinion I think you might be going about this in the wrong way.  I
would write two abstract classes, one containing the getCustomer method and
the other containing the setCustomer method.  Both classes should have
instancing 'Private - Not Creatable'.  Create a base class that implements
both abstract classes.  Inside the base class create an instance of each
abstract class and in the implemented methods delegate to the instantiated
abstract class object methods.

In the client code you'll need to do this if you want to setCustomer.

Dim pvNewCustomer As clsCustomer
Dim pvIsetCustomer As IsetCustomer
Set pvNewCustomer = New clsCustomer
Set pvIsetCustomer = pvNewCustomer

(alternatively you can do this in the class initialise for the base class).

Under MTS you can setup two roles, one to get, and one to get and set.
Allocate these roles to the interfaces.  Presto.  The impression I get is
that Implements is their fundamentally to allow the grouping of methods and
properties into interfaces.  I think sharing between interfaces may be wrong
and complicating things when you don't really need to.

The above is what I have done under MTS and it works.

Dominic Mitchell

Quote:

>Hello!

>I am currently writing some ActiveX dll:s which implements different
>interfaces.
>Here is the problem:

>I have two interfaces.
>Interface A support method :  getCustomer and setCustomer
>Interface B supports only  method : getCustomer

>When I then writes a COM objects which implements both of
>these interfaces. The method getCustomer needs to be written
>two times.  It will look something like :
>:
>Private Function A_getCustomer()
>    Do some thing
>End Function
>Private Function  B_getCustomer()
>    Do the same thing as the function above
>End Function
>:

>Is there a way to let both interfaces use the same
>method?

>By the way is there anybody who now some good book covering IDL
programming?

>Salute
>/David



Thu, 27 Jul 2000 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Reuse code when interfaces implements the same method

2. Implemented Interface Method Auto Insertion?

3. IMPLEMENTING AN INTERFACE MADE FROM ANOTHER INTERFACE

4. Implementing an interface made from another interface

5. IMPLEMENTING AN INTERFACE MADE FROM ANOTHER INTERFACE

6. Implementing an interface made from another interface

7. How do I reuse code in the Code-Behind section of an ASPX page

8. Reusing an Object Interfaced to DECommand

9. Compatibility with old interfaces/Reuse of old implementations

10. Remove Interface Methods from class methods

11. How to reuse code in Access ?

12. Reuse of Code OCX?

 

 
Powered by phpBB® Forum Software