DEV Community

aaannvv
aaannvv

Posted on

The Four Hidden Shapes Behind Every Design Pattern (The 30-Second Revision Table)

Most engineers memorize design patterns as 23 names. Senior engineers see four shapes. If you can identify the shape, you can derive the pattern on demand — which is what actually matters when you're in front of a whiteboard or a code review.

Shape 1: "I control who makes this" (Creational)

When construction is complex, expensive, or needs central control:

  • Singleton: one instance + global access
  • Factory Method: subclass decides the product
  • Abstract Factory: a family of products
  • Builder: step-by-step assembly
  • Prototype: clone over construct

The framework tells: Spring beans default to singleton scope. Calendar.getInstance is a Factory Method. StringBuilder is a Builder.

Shape 2: "I glue things together" (Structural)

When you need to compose or adapt existing pieces:

  • Adapter: interface converter (HandlerAdapter in Spring MVC)
  • Decorator: stackable behavior (the entire java.io stream family)
  • Proxy: access control (Spring AOP is dynamic proxy at scale — JDK vs CGLIB is a top-3 interview question)
  • Facade: one front door (SLF4J)
  • Composite: tree = leaf (MyBatis's MixedSqlNode)
  • Flyweight: shared granularity (Integer.valueOf caches -128 to 127)
  • Bridge: split hierarchies (JDBC drivers)

Shape 3: "I coordinate behavior" (Behavioral)

When objects need to communicate without coupling:

  • Strategy: swappable algorithm (Comparators)
  • Template Method: skeleton + hooks (JdbcTemplate, AQS)
  • Observer: pub/sub notify (Spring's ApplicationEvent)
  • Chain of Responsibility: pass-along handling (Servlet Filter chains, Spring HandlerInterceptor)
  • Command: request as object (Runnable, undo stacks)
  • Iterator: sequential access (for-each)
  • plus Mediator, Memento, State, Visitor

Shape 4: "One trick per pattern" (the trap)

The interview trap: knowing the name but not the boundary. Decorator vs Proxy — same structure, different intent. Factory Method vs Abstract Factory — one product via subclassing vs a family via composition. Abstract Factory is often built from many Factory Methods.

The 30-second revision table

Pattern | One-liner | Framework sighting
Singleton | One instance + global access | Spring beans (default scope)
Factory Method | Subclass decides product | BeanFactory, Calendar.getInstance
Proxy | Access control | Spring AOP (JDK/CGLIB)
Decorator | Stackable behavior | java.io streams
Template Method | Skeleton + hooks | JdbcTemplate, AQS
Chain of Resp. | Pass-along handling | Filter/Interceptor chains
Strategy | Swappable algorithm | Comparators
Observer | Pub/sub notify | ApplicationEvent

If you can fill this table from memory AND explain why Spring AOP is a Proxy while Filter chains are Chain of Responsibility — you pass the pattern screen.


I collected all 23 with real production scenarios, code skeletons, framework sightings, and interview traps — in Design Patterns Decoded. The value isn't the 23 names; it's knowing where to look when a design smells.

Top comments (0)