Skip to content

Instantly share code, notes, and snippets.

@sirmike
Last active May 6, 2018 19:32
Show Gist options
  • Save sirmike/9218449 to your computer and use it in GitHub Desktop.
Save sirmike/9218449 to your computer and use it in GitHub Desktop.
Washing
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