Skip to content

Factory Method Pattern

Woo Jin Jang edited this page Jul 11, 2025 · 1 revision

📚 Factory Method Pattern 설명

  • 클래스들의 관리와 생성을 담당하는 팩토리를 만들어 중간에 두면 클라이언트 코드에서는 클래스들의 세부 종류 변화에 신경쓸 필요가 없어진다.

[Ex1]

// Product interface
public interface Product {
    void create();
}
// 각 인터페이스를 구현한 상품
public class Electronics implements Product {
    @Override
    public void create() {
        System.out.println("Electronics product created.");
    }
}

// 각 인터페이스를 구현한 상품
public class Clothing implements Product {
    @Override
    public void create() {
        System.out.println("Clothing product created.");
    }
}

// 각 인터페이스를 구현한 상품
public class Book implements Product {
    @Override
    public void create() {
        System.out.println("Book product created.");
    }
}
// ProductFactory class
public abstract class ProductFactory {

    // Factory Method
    public abstract Product createProduct(String type);

    public Product orderProduct(String type) {
        Product product = createProduct(type);
        product.create();
        return product;
    }
}
// ConcreteProductFactory class (Concrete Factory)
public class ConcreteProductFactory extends ProductFactory {
    @Override
    public Product createProduct(String type) {
        if (type.equalsIgnoreCase("electronics")) {
            return new Electronics();
        } else if (type.equalsIgnoreCase("clothing")) {
            return new Clothing();
        } else if (type.equalsIgnoreCase("book")) {
            return new Book();
        } else {
            throw new IllegalArgumentException(
                "Unknown product type."
            );
        }
    }
}

📖 Java

📖 Kotlin

📖 Coroutine

📖 Spring

📖 Spring Security

📖 Spring Batch

📖 Reactive Programming

📖 Database

📖 MySQL

📖 Redis

📖 JPA

📖 QueryDsl

📖 MSA

📖 Kafka

📖 Apache Flink

  • [Apache Flink - Apache Flink Architecture]
  • [Apache Flink - Stream Processing]
  • [Apache Flink - Data Stream API & Window]
  • [Apache Flink - State Management]

📖 HTTP

📖 AWS

📖 Docker

📖 Kubernetes

📖 CI/CD

📖 Nginx

📖 Monitoring🥈

  • [Monitoring - Log Concept]
  • [Monitoring - Log Level & Filter]
  • [Monitoring - Logback]
  • [Monitoring - Log Collection with ELK Stack]
  • [Monitoring - Log Monitoring with Kibana]
  • [Monitoring - Building a Monitoring System with Spring Boot Actuator]
  • [Monitoring - Server Monitoring with Prometheus and Grafana with Discord Alerts]

📖 Test

📖 Effective Java 3/E

📖 Kotlin Academy - Effective Kotlin

📖 Kotlin Academy - 핵심편

📖 스프링으로 시작하는 리액티브 프로그래밍

📖 가상 면접 사례로 배우는 대규모 시스템 설계 기초 1

📖 가상 면접 사례로 배우는 대규모 시스템 설계 기초 2

📖 Clean Code

📖 리팩토링 2판

📖 주니어 백엔드 개발자가 반드시 알아야 할 실무 지식

📖 GraphQL

Clone this wiki locally