public static void Main() { List <IWaterVehicle> waterVehicles = new List <IWaterVehicle>(); MasterCraft myBoat = new MasterCraft(10, "good transmission", 68.0, 87.0); Pontoon mySlowBoat = new Pontoon(16, "old transmission", 44.0, 13.0); JetSki mySpeedBoat = new JetSki(2, "awesome transmission", 30.0, 100.99); waterVehicles.Add(myBoat); waterVehicles.Add(mySlowBoat); waterVehicles.Add(mySpeedBoat); waterVehicles.ForEach(vehicle => { vehicle.Start(); vehicle.Drive(); vehicle.Stop(); }); // Build a collection of all vehicles that fly // With a single `foreach`, have each vehicle Fly() // Build a collection of all vehicles that operate on roads // With a single `foreach`, have each road vehicle Drive() // Build a collection of all vehicles that operate on water // With a single `foreach`, have each water vehicle Drive() }
public static void Main() { // Build a collection of all vehicles that fly Cessna plane = new Cessna(); Jet plane2 = new Jet(); List <IAirbased> airList = new List <IAirbased>(); airList.Add(plane); airList.Add(plane2); // With a single `foreach`, have each vehicle Fly() foreach (var item in airList) { item.Fly(); } // Build a collection of all vehicles that operate on roads Motorcycle bike = new Motorcycle(); Truck truck = new Truck(); List <IGroundbased> groundList = new List <IGroundbased>(); groundList.Add(bike); groundList.Add(truck); // With a single `foreach`, have each road vehicle Drive() foreach (var item in groundList) { item.Drive(); } // Build a collection of all vehicles that operate on water JetSki ski = new JetSki(); Pontoon boat = new Pontoon(); List <IWaterbased> waterList = new List <IWaterbased>(); waterList.Add(ski); waterList.Add(boat); // With a single `foreach`, have each water vehicle Drive() foreach (var item in waterList) { item.Drive(); } }
public static void Main() { // Build a collection of all vehicles that fly // With a single `foreach`, have each vehicle Fly() Blimp blimp1 = new Blimp(); Cessna cessna1 = new Cessna(); List <IAirBased> thingsThatFly = new List <IAirBased>(); thingsThatFly.Add(blimp1); thingsThatFly.Add(cessna1); foreach (IAirBased thing in thingsThatFly) { thing.Fly(); } // Build a collection of all vehicles that operate on roads // With a single `foreach`, have each road vehicle Drive() Motorcycle motorcycle1 = new Motorcycle(); PickupTruck truck1 = new PickupTruck(); List <IVehicle> thingsOnRoad = new List <IVehicle>(); thingsOnRoad.Add(motorcycle1); thingsOnRoad.Add(truck1); foreach (IVehicle thing in thingsOnRoad) { thing.Drive(); } // Build a collection of all vehicles that operate on water // With a single `foreach`, have each water vehicle Drive() JetSki jet1 = new JetSki(); Pontoon pon1 = new Pontoon(); List <IVehicle> thingsOnWater = new List <IVehicle>(); thingsOnWater.Add(jet1); thingsOnWater.Add(pon1); foreach (IVehicle thing in thingsOnWater) { thing.Drive(); } }
static void Main(string[] args) { Aeronca aeronca1 = new Aeronca(); Helicopter helicopter1 = new Helicopter(); List <IAirVehicle> flying = new List <IAirVehicle>(); flying.Add(aeronca1); flying.Add(helicopter1); foreach (var x in flying) { x.Fly(); x.Drive(); } Console.WriteLine(""); FourWheeler newFour = new FourWheeler(); Scooter newScoot = new Scooter(); List <ILandVehicle> land = new List <ILandVehicle>(); land.Add(newFour); land.Add(newScoot); foreach (var x in land) { x.Drive(); } Console.WriteLine(""); JetSki newSki = new JetSki(); Pontoon newToon = new Pontoon(); List <IWaterVehicle> water = new List <IWaterVehicle>(); water.Add(newSki); water.Add(newToon); foreach (var x in water) { x.Drive(); } }
// Implementation in Homework4 private static void DecoratorPatternDemo() { IBoat myBassBoat = new Bass(new OutboardEngine(200), BoatColor.Metallic_Grey); Console.WriteLine(myBassBoat); myBassBoat = new FishFinderGear(myBassBoat); Console.WriteLine(myBassBoat); IBoat myPontoonBoat = new Pontoon(new InboardEngine(350), BoatColor.Metallic_Grey); Console.WriteLine(myPontoonBoat); myPontoonBoat = new RefrigerationUnit(myPontoonBoat); Console.WriteLine(myPontoonBoat); IBoat myHouseBoat = new HouseBoat(new InboardEngine(550), BoatColor.Sandstone_Brown); Console.WriteLine(myHouseBoat); myHouseBoat = new EntertainmentCenter(myHouseBoat); Console.WriteLine(myHouseBoat); }