Skip to content
IRC-CodingIRC-Coding
SingletonObserverFactoryAdapterFacadeProxy

Design Patterns: Singleton, Observer, Factory, Adapter

Master key design patterns: Singleton, Observer, Factory, Adapter, Facade, Proxy. Usage, pros/cons, Java examples, and exam questions.

S

schutzgeist

1 min read
Design Patterns: Singleton, Observer, Factory, Adapter

Singleton, Observer, Factory, Adapter, Facade, Proxy

This post is a quick reference to six common patterns, complete with exam prep, examples, and key takeaways.

In a Nutshell

Design Patterns provide proven solutions to recurring structural and communication problems.

Quick Definitions

  • Singleton: ensures exactly one instance (e.g., configuration, logger)
  • Observer: implements Publish/Subscribe for events (e.g., UI updates)
  • Factory: encapsulates object creation
  • Adapter: translates incompatible interfaces
  • Facade: presents a unified, simple API for a subsystem
  • Proxy: acts as a stand-in for access control, caching, logging, and lazy loading

Exam Essentials

  • Singleton: single instance, global access
  • Observer: event decoupling
  • Factory: flexible object creation (key for IHK exams)
  • Adapter: integration and compatibility
  • Facade: simplified interface
  • Proxy: access control and caching (security)
  • Always document and justify pattern choices

Core Components

  1. Singleton constructor pattern
  2. Observer interface contract
  3. Factory create() method
  4. Adapter mapping logic
  5. Facade API layer
  6. Proxy access gate

Practical Example (Singleton in Java)

public class ConfigManager {
  private static ConfigManager instance;
  private ConfigManager() {}
  public static ConfigManager getInstance() {
    if (instance == null) {
      instance = new ConfigManager();
    }
    return instance;
  }
}

Strengths and Weaknesses

Strengths

  • Reusable solutions across projects
  • Battle-tested structures
  • Improved team communication

Weaknesses

  • Misapplication leads to unnecessary complexity
  • Singleton can complicate unit testing
  • Observer chains can cascade unintentionally

Common Exam Questions (Quick Answers)

  1. What does Singleton achieve? Guarantees exactly one instance.
  2. When should you use Observer? When multiple objects need to react to a state change.
  3. Why use Factory instead of calling new everywhere? It centralizes and decouples creation logic.

Further Reading

  1. https://refactoring.guru/design-patterns
  2. https://github.com/iluwatar/java-design-patterns
Back to Blog
Share:

Nächster Artikel in Software Architecture

Weiterlesen
Design Patterns: Singleton, Observer, Factory & More

Related Posts