mercredi 26 février 2020

Is abstract design pattern a good option for creating scalable application [closed]

I am learning classical design patterns and came across factory and abstract factory-like below

namespace factorydesign
{
    interface IHomeAutomation
    {
        void Activate();
    }
}

namespace factorydesign
{
    class LightsConcreate : IHomeAutomation
    {
        public void Activate()
        {
            Console.WriteLine("Lights have been turned On");
        }
    }
}

namespace factorydesign
{
    class AirConditionerConcreate : IHomeAutomation
    {
        public void Activate()
        {
            Console.WriteLine("Aircondition is Activated");
        }
    }
}

namespace factorydesign
{
    class HomeAutomationFactory
    {
        public IHomeAutomation Selection(string sel)
        {
            switch(int.Parse(sel))
            {
                case 1:
                    return new LightsConcreate();
                case 2:
                    return new AirConditionerConcreate();
                default:
                    return new LightsConcreate();
            }
        }
    }
}

namespace factorydesign
{
    class Program
    {
        static void Main(string[] args)
        {
            HomeAutomationFactory HAF = new HomeAutomationFactory();

            Console.WriteLine("Hello i am Sakura. I am your smart home Automation System");
            Console.WriteLine("For Turning Lights Press 1");
            Console.WriteLine("For Aircondition Press 2");
            string selection =Console.ReadLine();

            IHomeAutomation selObject = HAF.Selection(selection);

            selObject.Activate();
        }
    }
}

I have the above home automation system where users can activate lights or air-condition.

Let's suppose tomorrow I need to scale this up. Let's say like add light brightness setting, control lights in one room, or increase temperature, sleep mode for air-condition and so on.

So how should I set up my application when I know there will be scalabilities in near future?

Aucun commentaire:

Enregistrer un commentaire