User Tools

Site Tools



This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
principles:open-closed_principle [2013-06-15 15:40] [Context]
principles:open-closed_principle [2018-09-26 11:52] [Examples]
Line 1: Line 1:
-====== Open-Closed Principle ======+====== Open-Closed Principle ​(OCP) ======
 ===== Variants and Alternative Names ===== ===== Variants and Alternative Names =====
Line 71: Line 71:
 ===== Examples ===== ===== Examples =====
 +===Client Repository=== 
 +Let's say the high-level module (your business logic), wants to be able to add or remove clients to the database. Instead of it talking to the database directly, it defines an interface called ClientRepository which contains the methods the business logic needs ([[dependency_inversion_principle|DIP]]). Now you go along and implement a MySQLClientRepository. Some time in the future, you are asked to switch to an oracle database. You can now, without modifying any code from your business logic, switch to the oracle database: by extending ClientRepository to implement OracleClientRepository. You just need to wire an OracleClientRepository instance to the business logic and you have made the switch without modifying any business logic code.
 ===== Description Status ===== ===== Description Status =====
 /* Choose one of the following and comment out the rest: */ /* Choose one of the following and comment out the rest: */
Line 83: Line 84:
   * [[http://​​ArticleS.UncleBob.PrinciplesOfOod|ButUncleBob:​ Principles of OOD]]   * [[http://​​ArticleS.UncleBob.PrinciplesOfOod|ButUncleBob:​ Principles of OOD]]
 +===== Discussion =====
 +Discuss this wiki article and the principle on the corresponding [[talk:​principles:​Open-Closed Principle|talk page]].
principles/open-closed_principle.txt · Last modified: 2018-09-26 11:52 by