Encapsulate What Varies
One of the most common challenges in software development is dealing with change. Requirements evolve, technologies advance, and user needs also change. Therefore, it is crucial to write code that can adapt without causing a ripple effect of modifications throughout your program or application. This is where the principle of Encapsulate What Varies comes into play.
What does it mean?
The idea behind this principle is straightforward: isolate the parts of your code that are most likely to change and encapsulate them. By doing so, you create a protective barrier that shields the rest of your code from these elements that are subject to change. This encapsulation allows you to make changes to one part of your system without affecting others.
Techniques for achieving encapsulation
As we introduced, encapsulation helps in data hiding and exposing only the necessary functionalities. Here, we will present key techniques that enhance encapsulation in Python: polymorphism and the getters and setters techniques.
Favor Composition Over Inheritance
Program to Interfaces, Not Implementations
Loose Coupling
标签:Foundational,What,code,Python,Design,encapsulation,your,change From: https://www.cnblogs.com/zhangzhihui/p/18361849