I have a project which loads from database a XML file which defines a form for some user. XML is transformed into a collection of objects whose classes derive from single parent. Something likeControl -> EditControl -> TextBoxControl -> ContainterControl -> PanelThose classes are responsible for creation of GUI controls for three different enviroments: WinForms, DevExpress XtraReports and WebForms. All three frameworks share mostly the same control tree and have a common single parent (Windows.Forms.Control, XrControl and WebControl). So, how to do it?Solution a) Control class has abstract methodsControl CreateWinControl();XrControl CreateXtraControl();WebControl CreateWebControl();This could work but the project has to reference all three frameworks and the classes are going to be fat with methods which would support all three implementations.Solution b) Each framework implementation is done in separate projects and have the exact class tree like the Core project. All three implementations are connected using a interface to the Core class. This seems clean but I'm having a hard time wrapping my head around it. Does anyone have a simpler solution or a suggestion how should I approach this task?
How to structure my GUI agnostic project?
c#;object oriented design
If you have a tree of objects (and I do mean tree of objects, not tree of classes) of various types that you want to process in different ways, then the common approach is to use the visitor pattern.How would that look in your case? Your common project would contain an abstract class ControlTreeVisitor, which would look something like this (simplified by assuming there is no ContainterControl or EditControl):public abstract class ControlTreeVisitor{    protected virtual void VisitControl(Control control)    {        // dispatch to the appropriate Visit* method    }    protected virtual void VisitPanel(Panel panel)    {        foreach (var childControl in panel.Children)        {            VisitControl(childControl);        }    }    protected virtual void VisitTextBox(TextBox textBox)    {        // do nothing    }}Each GUI-specific project would then contain a concrete class that would inherit from this visitor class and would override all the Visit* methods to create the appropriate control tree for the given GUI library.There are some possible alternatives in the design of the visitor base class. For example, one variation would be to make it generic, where the type parameter would represent the  base class in the specific GUI library (e.g. class WebControlVisitor : ControlTreeVisitor<WebControl>). All Visit* methods would then return this type. This would make creating a tree of WebControls simpler.