I'm a little new to template design, and this is my first post on stackoverflow, so hopefully this question will make sense. Ive created an abstract factory for processing xml generating strings for different chart providers (dundas, flash, etc.). Below is the code of my factory (I can include it more if it helps.) Id like my client so that he can set properties that will be distributed among all types of diagrams (signature, animation, etc.). So the client could do something like this:
GraphCreator fusion = new FusionGraphs();
fusion.Caption = "Fusion 2D Line Chart";
What is the best way to do this? Right now I am setting the properties in the abstract creator so that the client can have access to them, but Im also have to duplicate these properties in my factory, so I can access them when building xml.
// this is an abstract factory
public interface IXMLFactory
{
IRoot makeRoot();
IRootAttrib makeRootAttrib();
INodes makeNodes();
INodeAttrib makeNodeAttrib();
}
// this is an abstract creator
public abstract class GraphCreator
{
public virtual Graph getGraph(Graph.Types graphType)
{
Graph graph;
graph = buildGraph(graphType);
graph.draw();
return graph;
}
public abstract Graph buildGraph(Graph.Types graphType);
}
// this is a specific creator
public class FusionGraphs : GraphCreator
{
Graph g = null;
IXMLFactory xmlFactory;
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;
}
}
source
share