static void Main(string[] args) { var list = new List <MapObject> { new Hotel { Name = "Hilton", Latitude = 34.4, Longitude = 27.8, Stars = 5 }, new Restaurant { Name = "Italia", Latitude = 36.7, Longitude = 30.1, Cuisine = Cuisine.Italian }, new BusStation { Name = "28 May", Latitude = 15.1, Longitude = 27.5, BusNumbers = { 26, 48, 55, 96 } } }; foreach (var item in list) { Console.WriteLine(item); Console.WriteLine(); } var exporter = new MapObjectExporter(); foreach (var item in list) { item.Export(exporter); } //var exporter = new MapObjectExporter(); //foreach (var item in list) //{ // if (item is Hotel) // exporter.ExportHotel(item as Hotel); // if (item is Restaurant) // exporter.ExportRestaurant(item as Restaurant); // if (item is BusStation) // exporter.ExportBusStation(item as BusStation); //} }
static void Main(string[] args) { List <MapObject> mapObjects = new List <MapObject>(); mapObjects.Add(new Hotel() { Name = "Absheron", Latitude = 40.12, Longitude = 41.34, Stars = 5 }); mapObjects.Add(new Restaurant() { Name = "Sheki", Latitude = 43.25, Longitude = 45.34, Cuisine = Cuisine.Traditional }); mapObjects.Add(new BusStop() { Name = "28 May", Latitude = 41.22, Longitude = 43.78, BusNumbers = { 1, 2, 14 } }); MapObjectExporter exporter = new MapObjectExporter(); foreach (var obj in mapObjects) { obj.Export(exporter); //if (obj is Hotel) //{ // exporter.ExportHotel(obj as Hotel); //} //if (obj is Restaurant) //{ // exporter.ExportRestaurant(obj as Restaurant); //} //if (obj is BusStop) //{ // exporter.ExportBusStop(obj as BusStop); //} } }
public override void Export(MapObjectExporter exporter) { exporter.ExportRestaurant(this); }
public override void Export(MapObjectExporter exporter) { exporter.ExportHotel(this); }
public abstract void Export(MapObjectExporter exporter);
public override void Export(MapObjectExporter exporter) { exporter.ExportBusStation(this); }