Im somewhat new to design patterns and this is my first post in stackoverflow, so hopefully this question will make sense. Ive created an abstract factory to handle generating xml strings for different chart vendors (dundas, flash, etc...). Below is a code outline of my factory (I can include more if it helps.) Id like for my client to be able to set properties that will be common among all types of charts (caption, animation, etc.) So a client could do something like this:
GraphCreator fusion = new FusionGraphs();
//set the props for the graph
fusion.Caption = "Fusion 2D Line Chart";
What is the best way to do this? Right now, Im setting properties in the abstract creator so the client can have access to them, but Im also having to duplicate these properties in my factory so I can have access to them in building the xml.
//this is the abstract factory
public interface IXMLFactory
{
//add interface methods
IRoot makeRoot();
IRootAttrib makeRootAttrib();
INodes makeNodes();
INodeAttrib makeNodeAttrib();
}
//this is the abstract creator
public abstract class GraphCreator
{
public virtual Graph getGraph(Graph.Types graphType)
{
//abstract product
Graph graph;
//abstract product creation
graph = buildGraph(graphType);
graph.draw();
return graph;
}
public abstract Graph buildGraph(Graph.Types graphType);
}
//this is the concrete creator
public class FusionGraphs : GraphCreator
{
Graph g = null;
//XML parts for fusion 2D multi series
IXMLFactory xmlFactory;
//use xml parts that are needed for the type of fusion graph requested
public override Graph buildGraph(Graph.Types graphType)
{
switch (graphType)
{
case Graph.Types.Single2DLine:
xmlFactory = new Fusion2DSingleXMLFactory();
g = new Single2DLineGraph(xmlFactory);
xmlFactory.Caption = base.Caption;
break;
case Graph.Types.Single2DBar:
xmlFactory = new Fusion2DSingleXMLFactory();
g = new Single2DBarGraph(xmlFactory);
break;
}
return g;
}
}