Jan 27, 2020 in JAVA
Q: Give me an example of design pattern which is based upon open closed principle?

1 Answer

0 votes
Jan 27, 2020

This is one of the practical questions I ask experienced Java programmer. I expect them to know about OOP design principles as well as patterns. Open closed design principle asserts that your code should be open for extension but closed for modification. Which means if you want to add new functionality, you can add it easily using the new code but without touching already tried and tested code.  There are several design patterns which are based upon open closed design principle e.g. Strategy pattern if you need a new strategy, just implement the interface and configure, no need to modify core logic. One working example is Collections.sort() method which is based on Strategy pattern and follows the open-closed principle, you don't modify sort() method to sort a new object, what you do is just implement Comparator in your own way.

Related questions

+1 vote
Jun 23 in Robotic Process Automation
0 votes
Oct 17, 2019 in Design Patterns
...