Skip to content
IRC-CodingIRC-Coding
SingletonObserverFactoryAdapterFacadeProxy

Design Patterns: Singleton, Observer, Factory & More

Master 6 essential design patterns: Singleton, Observer, Factory, Adapter, Facade, Proxy. Usage, pros/cons, Java examples.

S

schutzgeist

1 min read
Design Patterns: Singleton, Observer, Factory & More

Singleton, Observer, Factory, Adapter, Façade, Proxy

This post explains six common design patterns—with exam tips, examples, and quick reference tags.

In a Nutshell

Design patterns provide time-tested solutions to recurring structural and communication problems in software.

Quick Reference

  • Singleton: Ensures a single instance across the application (e.g., configuration manager, logger)
  • Observer: Implements publish/subscribe for event handling (e.g., UI updates)
  • Factory: Encapsulates object creation logic
  • Adapter: Makes incompatible interfaces work together
  • Façade: Provides a simplified API over a complex subsystem
  • Proxy: Acts as a gatekeeper for access control, caching, logging, or lazy loading

Key Exam Points

  • Singleton: one instance, global access point
  • Observer: decouples event producers from consumers
  • Factory: flexible, centralized object creation
  • Adapter: enables integration of incompatible components
  • Façade: reduces API complexity
  • Proxy: enforces access control and caching
  • 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. Façade API layer
  6. Proxy access control 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, proven solutions
  • Established best practices
  • Improves team communication and code reviews

Weaknesses

  • Misapplication leads to unnecessary complexity
  • Singleton can complicate unit testing
  • Observer chains can trigger unexpected cascades

Common Exam Questions (With Brief Answers)

  1. What does Singleton achieve? Guarantees exactly one instance of a class.

  2. When should you use Observer? When multiple objects need to react to state changes independently.

  3. Why use Factory instead of new everywhere? To centralize and decouple creation logic from client code.

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