Skip to content
IRC-Coding IRC-Coding
Design Patterns Singleton Observer Factory Adapter Iterator Strategy Decorator Template Method MVC

Design Patterns: Singleton, Observer, Factory, Adapter

Master proven design patterns: Singleton, Observer, Factory, Adapter, Iterator, Strategy, Decorator, Template Method, and MVC architecture.

S

schutzgeist

2 min read

Design Patterns – Singleton, Observer, Factory, Adapter, Iterator, Strategy, Decorator

This post is a definition of key concepts regarding important Design Patterns – including exam questions and tags.

In a Nutshell

Design Patterns are proven solution approaches for recurring problems in software development. They provide standardized design patterns for common situations and improve code quality, maintainability, and communication.

Compact Technical Description

Design Patterns were popularized by the “Gang of Four” (GoF) and describe tested solution strategies for typical problems in object-oriented programming. They categorize into Creational Patterns (instantiation patterns such as Singleton, Factory), Structural Patterns (structural patterns such as Adapter, Decorator) and Behavioral Patterns (behavioral patterns such as Observer, Strategy, Iterator). Patterns promote loose coupling, high cohesion and reusability. They are not finished algorithms, but abstract solution descriptions that must be adapted to specific contexts.

Exam-Relevant Key Points

  • Creational Patterns: Singleton, Factory, Abstract Factory, Builder
  • Structural Patterns: Adapter, Decorator, Facade, Proxy, Composite
  • Behavioral Patterns: Observer, Strategy, Iterator, Command, Template Method
  • Singleton: Global instance, thread-safe implementation
  • Observer: Publisher-Subscriber, loose coupling between objects
  • Factory: Object creation without knowing concrete classes
  • Adapter: Interface adaptation between incompatible classes
  • Iterator: Sequential access to collection elements without exposing internal structure
  • Strategy: Exchangeable algorithms through interface-based implementation

Core Components

  1. Singleton Pattern (global instance)
  2. Factory Pattern (object creation)
  3. Observer Pattern (observer pattern)
  4. Adapter Pattern (interface adaptation)
  5. Iterator Pattern (sequential access)
  6. Strategy Pattern (algorithm exchange)
  7. Decorator Pattern (dynamic extension)
  8. Template Method Pattern (algorithm skeleton)
  9. MVC Pattern (architecture pattern)
  10. Registry Pattern (central registration)

Practical Example

// Singleton Pattern Example
public class DatabaseConnection {
    private static DatabaseConnection instance;
    
    private DatabaseConnection() {
        // Private Constructor
    }
    
    public static synchronized DatabaseConnection getInstance() {
        if (instance == null) {
            instance = new DatabaseConnection();
        }
        return instance;
    }
}

// Observer Pattern Example
interface Observer {
    void update(String message);
}

class EmailNotification implements Observer {
    public void update(String message) {
        sendEmail(message);
    }
}

Explanation: Singleton ensures global instance, Observer enables notification on state changes.

Advantages and Disadvantages

Advantages

  • Proven solutions for known problems
  • Improved communication between developers
  • Promote loose coupling and high cohesion
  • Increase reusability and maintainability

Disadvantages

  • Can lead to unnecessary complexity
  • Learning curve for beginners
  • Sometimes over-engineering for simple problems
  • Require context-appropriate adaptation

Typical Exam Questions (with Short Answers)

  1. Two main categories of Design Patterns? Creational (instantiation), Structural (structure), Behavioral (behavior).

  2. Purpose of Singleton Pattern? Ensures that exactly one instance of a class exists and is globally accessible.

  3. Application of Observer Pattern? When multiple objects need to be informed about state changes of another object.

  4. What problem does Factory Pattern solve? Object creation without needing to know concrete classes in client code.

  5. Adapter vs. Decorator? Adapter adapts interfaces, Decorator adds functionality dynamically.

  6. Advantage of Iterator Pattern? Enables uniform access to different collection types without exposing internal structure.

  7. Use Strategy Pattern? When algorithms should be exchangeable without changing client code.

  8. MVC Pattern Components? Model (data), View (presentation), Controller (logic connecting Model and View).

Most Important Sources

  1. https://refactoring.guru/design-patterns
  2. https://de.wikipedia.org/wiki/Entwurfsmuster
  3. https://www.oracle.com/technical-resources/articles/j2ee/patterns

Design Patterns

Books about design patterns and software design

Design Patterns von Gang of Four

Design Patterns von Gang of Four

Bei Amazon ansehen

Affiliate-Link: Bei einem Kauf erhalten wir möglicherweise eine Provision.

Patterns of Enterprise Application Architecture von Martin Fowler

Patterns of Enterprise Application Architecture von Martin Fowler

Bei Amazon ansehen

Affiliate-Link: Bei einem Kauf erhalten wir möglicherweise eine Provision.

Refactoring von Martin Fowler

Refactoring von Martin Fowler

Bei Amazon ansehen

Affiliate-Link: Bei einem Kauf erhalten wir möglicherweise eine Provision.

Back to Blog
Share:

Related Posts