principles:open-closed_principle
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
principles:open-closed_principle [2021-02-01 23:31] – old revision restored (2020-12-10 07:51) 95.216.157.202 | principles:open-closed_principle [2021-05-11 22:13] – old revision restored (2021-03-25 15:33) 95.216.157.239 | ||
---|---|---|---|
Line 71: | Line 71: | ||
===== Examples ===== | ===== Examples ===== | ||
+ | ===User 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. | ||
===== 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