Facade pattern in C#

using System;

namespace CSharpBasics
{
    //FACADE PATTERN - http://www.dofactory.com/Patterns/PatternFacade.aspx
    //Provide a unified interface to a set of interfaces in a subsystem. 
    //Fa├žade defines a higher-level interface that makes the subsystem easier to use. 

    //It actually encapsulates features from different sub classes
    //Can take it as aggregation

    class Facade
    {
        private SubSystemOne _one;
        private SubSystemTwo _two;
        private SubSystemThree _three;
        public Facade()
        {
            _one = new SubSystemOne();
            _two = new SubSystemTwo();
            _three = new SubSystemThree();
        }
        public void MethodA()
        {
            Console.WriteLine("MethodA() ---- ");
            _one.MethodOne();
            _two.MethodTwo();
        }

        public void MethodB()
        {
            Console.WriteLine("MethodB() ---- ");
            _two.MethodTwo();
            _three.MethodThree();
        }
    }

    class SubSystemOne
    {
        public void MethodOne()
        {
            Console.WriteLine(" SubSystemOne Method");
        }
    }
    class SubSystemTwo
    {
        public void MethodTwo()
        {
            Console.WriteLine(" SubSystemTwo Method");
        }
    }
    class SubSystemThree
    {
        public void MethodThree()
        {
            Console.WriteLine(" SubSystemThree Method");
        }
    }
}
Add Comments :

Login

Register