Skip to content

Instantly share code, notes, and snippets.

@hvitorino
Created September 27, 2012 13:52
Show Gist options
  • Select an option

  • Save hvitorino/3794123 to your computer and use it in GitHub Desktop.

Select an option

Save hvitorino/3794123 to your computer and use it in GitHub Desktop.
Strategy Pattern com dicionário
using System;
using System.Collections.Generic;
namespace Bolar
{
class Program
{
static void Main(string[] args)
{
Bora.BolarUmBong.MandaVer();
Bora.BolarUmFino.MandaVer();
Console.ReadKey();
}
public enum TiposDeBeck
{
Bong,
Fino
}
public class Bora
{
private static Bora singleton;
static Bora()
{
singleton = new Bora();
}
private Dictionary<TiposDeBeck, Bolador> registroDeBoladores;
public Bora()
{
registroDeBoladores = new Dictionary<TiposDeBeck, Bolador>
{
{ TiposDeBeck.Bong, new BoladorDeBong() },
{ TiposDeBeck.Fino, new BoladorDeFino() }
};
}
public static Bolador BolarUmBong
{
get { return singleton.registroDeBoladores[TiposDeBeck.Bong]; }
}
public static Bolador BolarUmFino
{
get { return singleton.registroDeBoladores[TiposDeBeck.Fino]; }
}
}
public abstract class Bolador
{
public abstract void MandaVer();
}
public class BoladorDeBong : Bolador
{
public override void MandaVer()
{
Console.WriteLine("BONG: ########### ~~~~~~~~");
}
}
public class BoladorDeFino : Bolador
{
public override void MandaVer()
{
Console.WriteLine("FINO: ----- ~~~");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment