Last active
May 6, 2018 19:32
-
-
Save sirmike/9218449 to your computer and use it in GitHub Desktop.
Washing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.IO; | |
using System; | |
using System.Collections.Generic; | |
interface IWasher | |
{ | |
void Wash(); | |
} | |
class RedWaterWasher : IWasher | |
{ | |
public void Wash() | |
{ | |
Console.WriteLine("Washing with red water."); | |
} | |
} | |
class BlueWaterWasher : IWasher | |
{ | |
public void Wash() | |
{ | |
Console.WriteLine("Washing with blue water."); | |
} | |
} | |
class WashManager | |
{ | |
private List<IWasher> washers = new List<IWasher>(); | |
public void AddWasher(IWasher washer) | |
{ | |
washers.Add(washer); | |
} | |
public void WashAll() | |
{ | |
washers.ForEach(w => w.Wash()); | |
} | |
} | |
public class MyProgram | |
{ | |
public static void Main() | |
{ | |
WashManager manager = new WashManager(); | |
manager.AddWasher(new RedWaterWasher()); | |
manager.AddWasher(new RedWaterWasher()); | |
manager.AddWasher(new BlueWaterWasher()); | |
manager.AddWasher(new BlueWaterWasher()); | |
manager.WashAll(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment