Encapsulate What Varies
phrase
say it: “en-KAP-suh-layt wut VAIR-eez” /ɪnˈkæpsəleɪt wʌt ˈvɛriz/
The design idea of giving the part of a program that changes most often a home of its own, so the rest of the code only asks it questions.
What does encapsulate what varies mean?
Encapsulate what varies is the design idea of finding the part of a program that changes most often and giving it a home of its own, behind one wall, so the rest of the code only asks it questions. A food truck's specials change every week, so they get a Specials class of their own, and the price code asks it "any special today?" instead of having the specials written into it. Almost every design pattern fences off something that varies: a rule, which class to make, or who gets told.
In a sentence
- “The specials changed every week, so we followed encapsulate what varies and gave them a class of their own.”
Level: Apprentice · More OOP terms at this level
Updated