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;InputStreamReaderadapts anInputStreamto aReader, so it's an Adapter;Comparatoris 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.
Sign up to mark studied questions and save your progress.