Abstract Factory Pattern and Properties

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();

        //set the props for the graph
        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
{

    //add interface methods
    IRoot makeRoot();
    IRootAttrib makeRootAttrib();
    INodes makeNodes();
    INodeAttrib makeNodeAttrib();

}

// this is an 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 a specific 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;
    }


}
+3
source share
2 answers

, , , - , , , , , xmlFactory. , , . , , .

, . , , , " factory"? ? , - base.Caption, - FusionGraphs, GraphCreator, ?

+1

, , , factory factory. , (, ), factory, .

0

Source: https://habr.com/ru/post/1705342/


All Articles