static void Main(string[] args) { string endpoint = (args.Length == 0) ? "default endpoint" : args[0]; // old legacy code. or code we do not have access var xml_provider = new XmlStockDataProvider(endpoint); // adapter which adaptee old code to user interface var provider = new JsonStockDataProvider(xml_provider); // user code. it used xml format before. var dayly = provider.GetDaylyCounts(); var weekly = provider.GetWeeklyCounts(); var monthlyData = provider.GetMonthlyData(); Console.WriteLine(dayly + Environment.NewLine + weekly + Environment.NewLine + monthlyData); }
// takes old specification in constructor. public JsonStockDataProvider(XmlStockDataProvider xmlStockDataProvider) { XmlStockDataProvider = xmlStockDataProvider; }