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 revisionPrevious revision
Next revisionBoth sides next revision
principles:open-closed_principle [2018-09-26 11:51] – [Examples] 62.228.239.6principles:open-closed_principle [2018-09-26 11:52] – [Examples] 62.228.239.6
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: 2022-03-02 23:55 by tory