User Tools

Site Tools


principles:open-closed_principle

Differences

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

Link to this comparison view

Both sides previous revision Previous revision
principles:open-closed_principle [2018-09-26 11:51]
62.228.239.6 [Examples]
principles:open-closed_principle [2018-09-26 11:52] (current)
62.228.239.6 [Examples]
Line 71: Line 71:
 ===== Examples ===== ===== Examples =====
  
-===User Repository=== +===Client ​Repository=== 
-Let's say the high-level module (your business logic), wants to be able to add or remove ​users 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.+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: */
principles/open-closed_principle.txt · Last modified: 2018-09-26 11:52 by 62.228.239.6 · Currently locked by: 54.36.150.190