I am working on a telecom project. I have implemented Open/Closed principle in my project. Below are my classes.

MainServiceClass.CS

public abstract class BaseServiceClass
{
    public abstract IEnumerable<string> GetServiceData();
    public abstract IEnumerable<string> GetDashBoardData();
}

Web_Service.CS

public class WebServiceClass : BaseServiceClass
{
    public override IEnumerable<string> GetServiceData()
    {
        List<string> MyList = new List<string>();
        return MyList;
    }

    public override IEnumerable<string> GetDashBoardData()
    {
        List<string> MyList = new List<string>();
        return MyList;
    }
}

Voice_Service.CS

public class VoiceSericeClass : BaseServiceClass
{
    public override IEnumerable<string> GetServiceData()
    {
        List<string> MyList = new List<string>();
        return MyList;
    }

    public override IEnumerable<string> GetDashBoardData()
    {
        List<string> MyList = new List<string>();
        return MyList;
    }
}

In the future, If I need to implement Video service, I will create a new Video_Service class.I believe that I will achieve Open/Close principle.

If I need to add a new method in my MainServiceClass.cs , I will add a new Method (GetNewTypeOfData()).

Question : Here, I am modifying a class. Still, am I following OCP? Or, is there any way to add new method in the MainServiceClass.cs??

Please suggest.

P.S. I need to implement this method in all the derived classes i.e. Web_Service.cs, Voice_Service.cs, and Video_Service.cs

Related posts

Recent Viewed