Sorry for not being more clear on this, as the article actually treats three different subjects.Originally Posted by high_flyer
My question is regarding the last article, called "Multiple inheritance".
Three different wrappers? Why would they be necessary, as there only needs to be one general wrapper which provided for various of the shared functions (plus the added advantage of being able to treat and manage them as the same object)?Now, regarding your inheritance design:
A wrapper is made, when you want to have a part of a code that always does the same work with the same API, but that the objects it operates on might change (polymorphysem).
So in your case I would say you need three such wrappers:
-A Table object interface
-A graph object interface
-A text object interface
- If there are any custom (i.e not QWidget) methods all these object share then you can also make an interface that binds all these classes in a common wrapper for these operations
This is a rather large application.NOTE: such interfcae design schemes make sence for larger applications or for code that is often used in various situations, not that much for small and specific applications)
That's what's happening already, but there are numerous situations where the three different object classes have to reimplement the same functions to provide certain functionality, but there is no interface to mandate the implementation of them.You can use the fact they all derive from QWidget for all operations that are derived from QWidget, and in these places use a QWidget pointer (so you will be able to access all objects on these oprations regardless of which derived type the object is currently).
Well, a single inheritance solution using a shared Document class would be a solution, but as such you will need to create a "has a" type of interface, which passes the function calls to the object (i.e. from Table to the QTable). This carries several problems as you need to hijack a lot of things to make it appear as though it actually is a QTable. Reimplementing may be a harsh word, as you "pass the buck", but effectively you need to provide the complete QTable interface, for starters, and a QTextEdit interface for the Text documents.I didn't understand this in respect to the code you posted.
You will have to write your own code for each custom class, thats what deriving is all about.
What Qt code would need to REimplement?
your Interface class is not needed, your wrapper class can offer that functionality.
The problem stems from the face that the three major objects are in fact already base classes for more specific classes.
Bookmarks