Creational vs Structural vs Behavioral Patterns
Fast recall
Quick revision
Core answer
Interview-ready guide
Interview answer
Design patterns fall into three categories based on the type of problem they solve.
Creational patterns handle object creation — they give you flexibility in how objects get instantiated.
For example, Singleton ensures you only ever have one instance of a configuration manager, and Factory lets you create different payment processors based on the country. Structural patterns deal with composition — how you combine objects into larger structures. Adapter is a good example.
If you're integrating a legacy XML parser with a new JSON API, Adapter bridges the gap. Decorator's another one — you'd use it to add logging or caching to an existing service without changing its code. Behavioral patterns manage interaction — how objects communicate and divide responsibilities.
Strategy lets you swap algorithms at runtime, like choosing different discount calculation rules. Observer's about broadcasting — when an order status changes, multiple listeners like email service and analytics service get notified. The key is recognizing which type of problem you're facing.
If you're fighting with object creation, look at Creational. If classes don't fit together, think Structural. If behavior needs to vary or objects need to communicate, it's Behavioral.
In a Spring Boot cart service, you'd see all three: Factory creating cart repositories, Decorator adding transaction handling, and Observer notifying inventory when items are added.
Creational vs Structural vs Behavioral Patterns
Direct Answer
Creational patterns control how objects are instantiated (Singleton, Factory), Structural patterns define how objects are composed into larger structures (Adapter, Decorator), and Behavioral patterns govern how objects interact and distribute responsibilities (Strategy, Observer).
Code Example
// CREATIONAL - control instantiation (Factory)
interface Payment { void pay(double amt); }
class Card implements Payment { public void pay(double a){ System.out.println("card " + a); } }
class PaymentFactory { static Payment of(String type){ return new Card(); } }
// STRUCTURAL - compose objects (Decorator wraps a Payment)
class LoggedPayment implements Payment {
private final Payment inner;
LoggedPayment(Payment p){ this.inner = p; }
public void pay(double a){ System.out.println("log: paying"); inner.pay(a); }
}
// BEHAVIORAL - vary behavior at runtime (Strategy)
interface Discount { double apply(double price); }
class Festive implements Discount { public double apply(double p){ return p * 0.8; } }
public class Demo {
public static void main(String[] args){
Payment p = new LoggedPayment(PaymentFactory.of("card")); // creational + structural
Discount d = new Festive(); // behavioral
p.pay(d.apply(100));
}
}
Common Mistakes & Pitfalls
- Category Confusion: Freshers often call Adapter a Creational pattern because it 'creates' compatibility, but it's Structural — it changes how objects fit together, not how they're instantiated.
- Memorizing Without Context: Listing "Singleton is Creational, Observer is Behavioral" without explaining that Singleton solves the 'one instance' creation problem while Observer solves the 'one-to-many notification' communication problem.
- Pattern Over Problem: Choosing a pattern name before identifying which category of problem you're facing — you should recognize 'this is a creation problem' before jumping to 'I need Factory'.
Check your understanding
Answer these without looking back at the article.
- What is the Facade pattern and when would you use it?
- What is the Proxy pattern and how does it differ from Decorator?
Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.