가장 많이 묻는 면접 질문과 답변 & 온라인 테스트
면접 준비, 온라인 테스트, 튜토리얼, 라이브 연습을 위한 학습 플랫폼

집중 학습 경로, 모의고사, 면접 준비 콘텐츠로 실력을 키우세요.

WithoutBook은 주제별 면접 질문, 온라인 연습 테스트, 튜토리얼, 비교 가이드를 하나의 반응형 학습 공간으로 제공합니다.

Chapter 2

Creational Patterns Part 1: Singleton and Factory Method

Understand how object creation choices shape design through Singleton and Factory Method, including their correct use cases, misuse cases, and Java examples.

Inside this chapter

  1. Why Creational Patterns Matter
  2. Singleton Pattern
  3. Factory Method Pattern
  4. Tradeoffs and Misuse
  5. Real-World Usage Snapshot

Series navigation

Study the chapters in order for the clearest path from first design principles to advanced Java architecture, framework usage, and interview-level pattern mastery. Use the navigation at the bottom of the page to move through the full tutorial smoothly.

Tutorial Home

Chapter 2

Why Creational Patterns Matter

Object creation is often treated as trivial by beginners, but large systems reveal that construction decisions influence lifecycle, testing, dependency management, configuration, and extensibility. Creational patterns focus on how objects are created and how client code can remain decoupled from concrete classes.

Chapter 2

Singleton Pattern

The Singleton pattern ensures one instance of a class and provides controlled access to it. It is useful when a truly shared, process-wide concept exists, such as configuration, registry-like metadata, or certain caches. It is harmful when used as disguised global state.

public final class AppConfig {
    private static final AppConfig INSTANCE = new AppConfig();

    private AppConfig() {
    }

    public static AppConfig getInstance() {
        return INSTANCE;
    }
}

In modern Java, an enum-based singleton is often the safest implementation because it handles serialization and reflection concerns better.

Chapter 2

Factory Method Pattern

Factory Method moves object creation behind a method so subclasses or collaborators can decide which implementation to instantiate. This helps when creation depends on environment, data, configuration, or extension points.

public interface Notification {
    void send(String message);
}

public class EmailNotification implements Notification {
    public void send(String message) {
        System.out.println("Email: " + message);
    }
}

public abstract class NotificationCreator {
    public abstract Notification createNotification();

    public void deliver(String message) {
        Notification notification = createNotification();
        notification.send(message);
    }
}

public class EmailNotificationCreator extends NotificationCreator {
    @Override
    public Notification createNotification() {
        return new EmailNotification();
    }
}
Chapter 2

Tradeoffs and Misuse

  • Singleton can hurt testability and hide dependencies.
  • Factory Method can add unnecessary hierarchy if creation is simple.
  • Dependency injection frameworks often reduce the need for hand-written singleton and factory logic.
  • Use the pattern only when variability or lifecycle control justifies it.
Chapter 2

Real-World Usage Snapshot

Spring uses bean scopes and dependency injection to manage many responsibilities that older Java systems solved with manual singleton or factory code. Still, understanding these patterns helps developers reason about framework behavior and make better architectural choices outside the container as well.

Copyright © 2026, WithoutBook.