What is Channel Factory C#? Example.

Channel Factory enables you to create a communication channel to the service without a proxy. 

Channel Factory that creates and manages the various types of channels which are used by a client to send a message to various configured service endpoints.
   
Example 

class FactoryPatternCurrent
    {
        static void Main(string[] args)
        {
            while (true)
            {
                Console.WriteLine("enter your vehicles");
                string str = Console.ReadLine();
                Factory obj = new Factory();
                obj.CreateObj(str).Name();
                Console.ReadKey();
            }

        }
    }
    class Factory
    {
        public Vehicles CreateObj(string type)
        {
            Vehicles obj = null;
            switch (type)
            {
                case "car":
                    obj = new Car();
                    break;
                case "bike":
                    obj = new Bike();
                    break;
                default:
                    obj = new Car();
                    break;
            }
            return obj;
        }
    }
    interface Vehicles
    {
        void Name();
    }

    class Car : Vehicles
    {
        public void Name()
        {
            Console.WriteLine("WagonR");
        }
    }
    class Bike : Vehicles
    {
        public void Name()
        {
            Console.WriteLine("Activa");
        }
    }
Share:

No comments:

Post a Comment

Wednesday, 4 September 2019

What is Channel Factory C#? Example.

Channel Factory enables you to create a communication channel to the service without a proxy. 

Channel Factory that creates and manages the various types of channels which are used by a client to send a message to various configured service endpoints.
   
Example 

class FactoryPatternCurrent
    {
        static void Main(string[] args)
        {
            while (true)
            {
                Console.WriteLine("enter your vehicles");
                string str = Console.ReadLine();
                Factory obj = new Factory();
                obj.CreateObj(str).Name();
                Console.ReadKey();
            }

        }
    }
    class Factory
    {
        public Vehicles CreateObj(string type)
        {
            Vehicles obj = null;
            switch (type)
            {
                case "car":
                    obj = new Car();
                    break;
                case "bike":
                    obj = new Bike();
                    break;
                default:
                    obj = new Car();
                    break;
            }
            return obj;
        }
    }
    interface Vehicles
    {
        void Name();
    }

    class Car : Vehicles
    {
        public void Name()
        {
            Console.WriteLine("WagonR");
        }
    }
    class Bike : Vehicles
    {
        public void Name()
        {
            Console.WriteLine("Activa");
        }
    }

No comments:

Post a Comment

Popular

Total Pageviews

Archive