Quote:Original post by Polymorphic OOP
For instance, now you have your wrapped NewInterface in a child of the OldInterface. So you return it and have a pointer to the OldInterface. Now how do you convert the OldInterface pointer from outside of that function to the NewInterface (remember that externally you can potentially have no knowledge of those additional types, as rsegal has claimed)? This is a situation that very well can occur and is what is described in the original posters problem as well as in my suggested scenerio.
NewInterface and OldInterface are not related. If you want a NewInterface you can get one from the application that gave you the OldInterface.
Quote:
In addition to the increase in the amount of code and the fact that the problem isn't fully solved, you are also using more dynamically allocated objects than you'd use with the suggested multiple inheritance model, which would only have the dynamic allocation of the child object (assuming you'd even need that object dynamically allocated, which isn't necessarily the case either). What's more is, the multiple inheritance model is most-likely much easier to understand since all you are doing is instantiating a child and interfacing with it via its bases, just like with any other public inheritance. No extra object types are introduced. All you need to know is C++ and the fact the the conversion is theoretically possible (unless, of course, you are working across executables as I described in my previous reply).
So the multiple inheritance model can be implemented in less code, without the addition of new types, and uses built-in functionality of the language making it less-likely for you to make an error (since the bulk of the work is done automatically by the compiler and not by a human who can understandably make mistakes).
Let's look at it another way. What you suggest is to make it easier to add new functionality as the inheritance will look after the support of old interfaces. Imagine you've got more than two versions. Imagine you have OldInterface, NewInterface, BrandNewInterface, LatestInterface, NextBigThingInterface, etc. Using it in this way will mean you end up with a class inheriting from all previous versions. This doesn't look good to me. It is difficult and error prone to understand what code is implementing what functionality for what version of the interface.
With my way of doing it ("he said d-oing"), your dependency upon old and legacy code is taken care of in one place, through a delegating class. Your new code really is new code. If you want to reuse some of the older code you can contain an object and use its functionality instead of inheriting it.
If it's not possible to use the new class with the limited old interface it won't be possible to write the delegating wrapper. I feel this better expresses the development of an interface. With your design it would be possible to get a handle on an object but not be able to meaningfully use it.