Home > Blockchain >  Does this violates open/closed principle?
Does this violates open/closed principle?

Time:10-31

I made a webapi with .NET Core and I have a "Startup" class. This class has a "ConfigureServices" method that says:

// This method gets called by the runtime. Use this method to add services to the container.

But every time i add a new service, i need to "modify" this method, but it violates the open/closed principle.

If I use use and "IF" and "ELSE" criteria to do the same thing as I am modifying this method.

So what do you think about this?

CodePudding user response:

It is quite the opposite. You are extending the method inside your own Startup, not modifying the base Startup. This article from wikipedia clearly states that in order to comply to open/closed principle

software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification

I didn't quite understand what you mean with the if/else part.

  • Related