Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            //FactoryMethod
            var shipFactory        = new ShipFactory();
            var fabricMethodClient = new FabricMethodClient(shipFactory);

            fabricMethodClient.Deliver();

            var cargoFactory = new CargoFactory();

            fabricMethodClient.SetTransportFactory(cargoFactory);
            fabricMethodClient.Deliver();

            //AbstractFactory
            var humanFactory          = new HumanUnitFactory();
            var abstractFactoryClient = new AbstractFactoryClient(humanFactory);

            abstractFactoryClient.DoSquad();

            var orkFactory = new OrkUnitFactory();

            abstractFactoryClient.SetUnitFactory(orkFactory);
            abstractFactoryClient.DoSquad();

            //Builder
            var opossumBuilder = new OpossumBuilder();
            var director       = new Director(opossumBuilder);
            var sectionalUnit  = director.GetUnit();

            sectionalUnit.DoStuff();

            var baldBuilder = new BaldBuilder();

            director.SetBuilder(baldBuilder);
            sectionalUnit = director.GetUnit();
            sectionalUnit.DoStuff();

            //Prototype
            var prototype = new PrototypeSample(2);

            prototype.SetProperty(1.0f);
            prototype.DoStuff();
            var clone = (PrototypeSample)prototype.Clone();

            clone.DoStuff();

            //Singleton
            Singleton.Instance.SingletonScream();

            //Adapter
            var adapterClient = new AdapterClient();

            adapterClient.DoStuff();

            //Bridge
            var bridgeClient = new BridgeClient();

            bridgeClient.DoStuff();

            //Composite
            var compositeClient = new CompositeClient();

            compositeClient.DoStuff();

            //Decorator
            var decoratorClient = new DecoratorClient();

            decoratorClient.DoStuff();

            //Facade
            var facadeClient = new Facade();

            facadeClient.DoStuff();

            //Flyweight
            var flyweightClient = new FlyweightClient();

            flyweightClient.DoStuff();

            //Proxy
            var proxyClient = new ProxyClient();

            proxyClient.DoStuff();

            //CoR
            var corClient = new CoRClient();

            corClient.DoStuff();

            //Command
            var commandClient = new CommandClient();

            commandClient.DoStuff();

            //Iterator
            var iteratorClient = new IteratorClient();

            iteratorClient.DoStuff();

            //Mediator
            var mediatorClient = new MediatorClient();

            mediatorClient.DoStuff();

            //Memento
            var mementoClient = new MementoClient();

            mementoClient.DoStuff();

            //Observer
            var observerClient = new ObserverClient();

            observerClient.DoStuff();

            //Strategy
            var strategyClient = new StrategyClient();

            strategyClient.DoStuff();

            //TemplateMethod
            var templateMethodClient = new TemplateMethodClient();

            templateMethodClient.DoStuff();

            //Visitor
            var visitorClient = new VisitorClient();

            visitorClient.DoStuff();
        }
Ejemplo n.º 2
0
        private static void RunChoice(int number)
        {
            switch (number)
            {
            case 1:
                AbstractFactorySample.Main();
                break;

            case 2:
                BuilderSample.Main();
                break;

            case 3:
                FactoryMethodSample.Main();
                break;

            case 4:
                PrototypeSample.Main();
                break;

            case 5:
                SingletonSample.Main();
                break;

            case 6:
                AdapterSample.Main();
                break;

            case 7:
                BridgeSample.Main();
                break;

            case 8:
                CompositeSample.Main();
                break;

            case 9:
                DecoratorSample.Main();
                break;

            case 10:
                FacadeSample.Main();
                break;

            case 11:
                FlyweightSample.Main();
                break;

            case 12:
                ProxySample.Main();
                break;

            case 13:
                ChainOfResponsibilitySample.Main();
                break;

            case 14:
                CommandSample.Main();
                break;

            case 15:
                InterpreterSample.Main();
                break;

            case 16:
                IteratorSample.Main();
                break;

            case 17:
                MediatorSample.Main();
                break;

            case 18:
                MementoSample.Main();
                break;

            case 19:
                ObserverSample.Main();
                break;

            case 20:
                StateSample.Main();
                break;

            case 21:
                StrategySample.Main();
                break;

            case 22:
                TemplateMethodSample.Main();
                break;

            case 23:
                VisitorSample.Main();
                break;

            default:
                break;
            }
        }