Video in progress

Which three groups are the GoF patterns divided into? Give one example of each.

Question / Examples — Creational: Who creates the object, and how? / Singleton, Factory Method, Abstract Factory, Builder, Prototype; Structural: How do classes fit together? / Adapter, Decorator, Proxy, Facade, Composite, Bridge, Flyweight; Behavioral: Who does what, who notifies whom? / Strategy, Observer, Template…

📖 Answer

Group Question Examples
Creational Who creates the object, and how? Singleton, Factory Method, Abstract Factory, Builder, Prototype
Structural How do classes fit together? Adapter, Decorator, Proxy, Facade, Composite, Bridge, Flyweight
Behavioral Who does what, who notifies whom? Strategy, Observer, Template Method, Command, State, Chain of Responsibility, Iterator

Familiar examples from the JDK:

  • StringBuilder, HttpClient.newBuilder(): Builder;
  • InputStreamReader adapts an InputStream to a Reader, so it's an Adapter;
  • Comparator is a Strategy: the sorting algorithm stays the same, and the comparison rule is swapped.

In an interview, reciting the groups isn't enough. If you can explain one from each group with an example from your own project, you leave a much stronger impression.