public void test() { IChart chart; chart = ChartFactory.GetChart("histo"); Assert.AreEqual(chart.GetType(), typeof(HistogramChart)); }
static void Main(string[] args) { IChart chart; chart = ChartFactory.GetChart("histo"); chart.Display(); Console.Read(); }
/// <summary> /// 简单工厂模式 /// </summary> /// <param name="args"></param> static void Main(string[] args) { IChart chart; //读取配置文件 string chartStr = ConfigurationManager.AppSettings["chartType"]; //通过静态工厂方法创建产品 chart = ChartFactory.GetChart(chartStr); chart.Display(); Console.ReadLine(); }
static void Main(string[] args) { var chartType = GetConfiguration("charttype"); if (string.IsNullOrEmpty(chartType)) { return; } IChartable chart = ChartFactory.GetChart(chartType); if (chart != null) { chart.Display(); } Console.ReadLine(); }
static void Main(string[] args) { /* * Product product; * product = Factory.GetProduct("A"); //通过工厂类创建产品对象 * product.MethodSame(); * product.MethodDiff(); */ Chart chart; //读取配置文件 string chartStr = ConfigurationManager.AppSettings["chartType"]; chart = ChartFactory.GetChart(chartStr); //通过静态工厂方法创建产品 chart.Display(); Console.Read(); }