Created
September 27, 2012 13:52
-
-
Save hvitorino/3794123 to your computer and use it in GitHub Desktop.
Strategy Pattern com dicionário
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; | |
| 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