Find What Is Varying and Encapsulate It

In Design Patterns: Elements of Reusable Object-Oriented Software, the Gang of Four suggests the following:

Consider what should be variable in your design. This approach is the opposite of focusing on the cause of redesign. Instead of considering what might force a change to a design, consider what you want to be able to change without redesign. The focus here is on encapsulating the concept that varies, a theme of many design patterns.[1]

[1] Gamma,E.,Helm,R.,Johnson,R.,Vlissides,J.,Design Patterns:Elements of Reusable Object-Oriented Software, Reading,Mass.:Addison-Wesley,1995,p.29.

[1] Gamma,E.,Helm,R.,Johnson,R.,Vlissides,J.,Design Patterns:Elements of Reusable Object-Oriented Software, Reading,Mass.:Addison-Wesley,1995,p.29. ...

Get Design Patterns Explained: A New Perspective on Object-Oriented Design now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.