tags:

views:

32

answers:

1

I have an ATL/COM-based DLL, written in VC++ 6.0. Until recently, there was a one-to-one correspondence between my COM interfaces and classes. For example, let's say there was a ICar interface; then there was also a CCar class which implemented it, and no class other than CCar implemented ICar, and CCar implemented no interface (of mine) other than ICar. Similarly, IPlane and CPlane. The definitions might be something like:

ICar had functions "StepOnGas" and "MaxPassengers"; IPlane had functions "LowerLandingGear" and "MaxPassengers".

Recently, I changed it so that there's an IVehicle interface, which has no corresponding CVehicle class, and which both CCar and CPlane implement. So:

ICar has "StepOnGas"; IPlane has "LowerLandingGear"; IVehicle has "MaxPassengers". CCar implements ICar and IVehicle; CPlane implements IPlane and IVehicle.

This is working fine, but it's a bit of a pain from the DLL client's perspective; they've got an ICar, and they want to know how many passengers it can hold. Previously, they could just ask it; now, they have to jump through the hoop of changing it into an IVehicle before they can ask it.

So what I'd like to do is more along the lines of this:

ICar has "StepOnGas" and "MaxPassengers"; IPlane has "LowerLandingGear" and "MaxPassengers"; IVehicle has "MaxPassengers". CCar still implements both ICar and IVehicle, and CPlane still implements both IPlane and IVehicle.

I want there to be one and only one "MaxPassengers" for CCar, and it to be accessible both from ICar and from IVehicle; similarly, one and only one "MaxPassengers" for CPlane, and it accessible both from IPlane and IVehicle.

Would this cause any problems? Would I have to do anything specific other than just add "MaxPassengers" to the IDL for ICar and IPlane?

In case it matters, clients of this DLL are written in both VC++ 6.0 and VB6.

Thanks in advance for any help.

+1  A: 

Simple answer: yes, you can

Even better: why don't you inherit ICar from IVehicle, that is you can extend IVehicle with new methods and name it ICar. This way your object can be QI'd for both interfaces and ICar will have all the methods a client needs to manipulate the object. This also allows ICar to be upcasted to IVehicle so both interface can share a single implementation (i.e. accessing MaxPassengers both on ICar and IVehicle executes the same C++ method).

Same for IPlane but the extension will include different methods.

wqw
Oh, that would be fantastic. I didn't know that you could do that in IDL. I will look into figuring out the syntax to do it.Thanks very much!
Ptah- Opener of the Mouth