I have a base class and several concrete classes that derive from it. Lets just say it looks like this:
abstract class Base
{
public int id;
public string baseVariable;
}
class ConcreteA extends Base
{
public string propertyA;
public float propertyB;
}
class ConcreteB extends Base
{
public decimal propertyC;
public RandomClass propertyD;
}
Lets just say the UI is a big open space with a bunch of concrete objects that derive from Base floating around in it. In this view all you would need is the general id and baseVariable properties to get what you need to display the generic objects. If you double click on one of the objects, it would then pop up a window where you could edit all the properties of the Base and Concrete objects within.
In that window, I want to have dynamically loaded tabs based on which type of concrete object I have, and statically loaded tabs that are used to modify common Base properties. Is there a good design pattern for implementing something like this?
It seems like I should avoid this:
class PopUpWindow
{
public PopUpWindow(object:Base)
{
tabs.add(BaseTab);
switch(typeOf(object))
{
case ConcreteA:
tabs.add(ConcreteATab);
case ConcreteB:
tabs.add(ConcreteBTab);
}
}
}
But I also don’t think I should be mixing UI stuff in the objects themselves like so:
public PopUpWindow(object:Base)
{
tabs.add(BaseTab);
tabs.addAll(object.TabsToShowOnEdit);
...
Any ideas or suggestions? Sorry for the long winded question. Thanks in advance.
One way is to have a factory in which you register view types based on model type:
Then you can easily use the factory when populating your PopupWindow: