100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace

Structural Design Patterns Cheat Sheet

Structural Design Patterns Cheat Sheet

Adapter, Decorator, Facade, and other Gang of Four structural patterns for composing classes and objects into larger, flexible structures.

2 PagesAdvancedMar 25, 2026

Adapter Pattern

Making an incompatible interface work with the client's expected interface.

python
class EuropeanSocket:    def voltage(self): return 230class USPlug:    def plug_in(self, socket):        raise NotImplementedErrorclass SocketAdapter(USPlug):    """Adapts a EuropeanSocket to the interface USPlug expects."""    def __init__(self, socket: EuropeanSocket):        self.socket = socket    def plug_in(self, _=None):        return self.socket.voltage() / 2  # step down to ~115Vadapter = SocketAdapter(EuropeanSocket())adapter.plug_in()  # 115.0

Decorator Pattern

Adding responsibilities to an object dynamically without subclassing.

python
class Coffee:    def cost(self): return 2.0    def description(self): return "Coffee"class MilkDecorator:    def __init__(self, coffee): self._coffee = coffee    def cost(self): return self._coffee.cost() + 0.5    def description(self): return self._coffee.description() + " + Milk"class SyrupDecorator:    def __init__(self, coffee): self._coffee = coffee    def cost(self): return self._coffee.cost() + 0.3    def description(self): return self._coffee.description() + " + Syrup"order = SyrupDecorator(MilkDecorator(Coffee()))order.description()  # "Coffee + Milk + Syrup"order.cost()          # 2.8

Facade Pattern

Hiding subsystem complexity behind one simple interface.

python
class CPU:    def start(self): print("CPU starting")class Memory:    def load(self): print("Memory loading")class HardDrive:    def read(self): print("Disk reading")class ComputerFacade:    """Simple interface hiding the complexity of the subsystems."""    def __init__(self):        self.cpu, self.memory, self.disk = CPU(), Memory(), HardDrive()    def start(self):        self.cpu.start()        self.memory.load()        self.disk.read()ComputerFacade().start()  # one call instead of three

Structural Pattern Catalog

One-line definitions of the classic Gang of Four structural patterns.

  • Adapter- Convert the interface of a class into another interface clients expect, letting incompatible classes work together
  • Decorator- Attach additional responsibilities to an object dynamically, without altering its class or affecting other instances
  • Facade- Provide a simplified, unified interface to a complex subsystem of classes
  • Composite- Compose objects into tree structures and let clients treat individual objects and compositions uniformly
  • Proxy- Provide a placeholder/surrogate for another object to control access to it, e.g. lazy loading or caching
  • Bridge- Decouple an abstraction from its implementation so the two can vary independently
  • Flyweight- Share common state across many fine-grained objects to reduce memory usage
Pro Tip

Decorator and inheritance both extend behavior, but Decorator does it at runtime and composably — prefer it over creating a new subclass for every feature combination (avoid a MilkAndSyrupCoffee / SyrupOnlyCoffee explosion).

Was this cheat sheet helpful?

Explore Topics

#StructuralDesignPatterns#StructuralDesignPatternsCheatSheet#Programming#Advanced#AdapterPattern#DecoratorPattern#FacadePattern#StructuralPatternCatalog#OOP#CheatSheet#SkillVeris
Advertisement
Sri Hayavadhana Info-Tech

Professional Web Designing Services

  • Responsive Websites
  • E-commerce Solutions
  • SEO Friendly Design
  • Fast & Secure
  • Support & Maintenance
Get a Free Quote

Share this Cheat Sheet