Hello fellow programmers,
Some may know me from the C part of the forum where I tend to post more often. In this case, I am in need of some guidance regarding a C++ issue that has come up lately in one of my projects. I have researched previous forum postings regarding similar issues but I didn't find any thread addressing this one in particular.
The issue I am having is a design one rather than a coding one, so I am just looking for ideas on how to tackle the problem not code itself. Since I cannot actually post my code here, I will provide a similar abstraction of my problem below.
Let's say that I have an abstract class called Dimension which is derived by three other classes A, B and C. Dimension just contains 2 pure virtual methods which need to be implemented by derived classes. Now, another class, called Monitor needs to manage a collection of Dimension derived classes.
One major requirement however is that this code is easily extended to include additional user programmer defined Dimension derived classes and as such, the Monitor class can only interface with the Dimension objects in its collection through the two methods declared by class Dimension, and implemented by its derived classes.
Now, normally that could easily be represented by having an STL container of Dimension* objects and then using polymorphism to call the appropriate method in the derived class. That is pretty much C++ Polymorphism 101, however, here is the twist in this case: the collection of Dimensions in the Monitor class has to have unique types. Therefore, for instance, you cannot have 2 A class types in that collection, but you can have any combination of derived classes which includes just one instance of each class type.
My questions is: is there a design flaw here, or is there a solution to address this problem in a c++ environment?
Thanks in anticipation,