Adapter Pattern
noun
say it: “uh-DAP-ter PAT-urn” /əˈdæptər ˈpætərn/
A design pattern that wraps one thing so it fits the shape the rest of your code expects.
What is Adapter Pattern?
The Adapter pattern puts a small class between your code and a class that doesn't fit, the way an interpreter lets two people who don't share a language talk. Your code calls the interface it expects, and the adapter turns each call into the other class's own methods.
public class LumoLightAdapter : ILight
{
private readonly LumoLight lumo = new();
public void On() => lumo.SetPower(true);
public void Off() => lumo.SetPower(false);
}
In a sentence
- “The Adapter pattern let the old receipt printer work with the bakery's new code.”
Level: Freelancer · More OOP terms at this level
Updated