![]() Overwriting the required behaviors from the class.When needs to extend functionality – avoid tight coupling, don’t use if-else/switch-case logic, do code refactoring as required. However, if you correctly structure your classes and their dependencies, you can add functionality without editing existing source code.ĭesign and code should be done in a way that new functionality should be added with minimum or no changes in the existing code. These two parts of the principle appear to be contradictory. “Closed for modification” means that once you developed a class you should never modify it, except to correct bugs. “Open to extension” means that you should design your classes so that new functionality can be added as new requirements are generated. So, we should modify our class only at the time of bug fixing. Of course, the one exception to the rule is when fixing bugs in existing code. Therefore, we also stop causing potential new bugs in an otherwise happy application. In doing so, we stop ourselves from modifying existing code. If we consider our software component as a class, then Classes should be open for extension, but closed for modification. Simply put, Software components like classes, modules, and functions should be open for extension but closed for modifications. The principle says, “Software components should be open for extension, but closed for modification”. What are the Design Patterns that follow Open Closed Principle?.What is the limitations of Open Closed Principle?.What is the benefits of Open Closed Principle?. ![]() What are the ways of extending a class ?. ![]()
0 Comments
Leave a Reply. |