How to compose a decorated class hierarchy without copying data
I have three classes that are related hierarchically:
-
Pattern
which has a protected field of_panels
typestd::vector<Panel>
. -
Panel
, in turn, has a protected field_edges
that is of typestd::vector<Edge>
. -
Edge
finally has a protected field_verts
that is of typestd::vector<Eigen::Vector2f>
.
I also have a pure virtual class Renderable
that has a pure virtual function virtual void render()
. I want to create specialized versions of each of my three classes that inherit from Renderable
, for example:
class VPattern : public Pattern, public Renderable
{
public:
void render() { ... }
protected:
...
private:
...
}; // class VPattern
However, the field _panels
will contain instances Panel
, not VPanel
. This would mean that I would have to put the drawing logic for Edge
and Panel
into the paint function Pattern
, which is clearly not ideal.
Is there any other approach here that I can't see to avoid all this? Would using a wrapper class be a more appropriate approach?
source to share