생산 비용을 줄이기
Motivation
- Rather than creation, use clone!
Intent
- Prototype is a creational design pattern that lets you copy existing objects without making your code dependent on their classes.
Implementation

Client
- 프로토타입에게 자신을 복사해서 새로운 객체를 줄것을 요청
Prototype
- 복제를 위한 인터페이스 제공
ConcretePrototype
-clone
메소드의 구현 제공
The Prototype pattern is available in Java out of the box with a
Cloneable
interface.See code example at Here
Applicablity
- Use the Prototype pattern when your code shouldn’t depend on the concrete classes of objects that you need to copy.
- Use the pattern when you want to reduce the number of subclasses that only differ in the way they initialize their respective objects. Somebody could have created these subclasses to be able to create objects with a specific configuration.
Pros and Cons
Pros
구체 클래스의 결합없이 복제 기능 제공
반복되는 초기화 코드 제거
복잡한 객체를 더 편하게 생성
Cons
복잡한 객체의 복제를 구현할때는 조심해야함 (순환 참조 등)
Relations with Other Patterns
- 많은 디자인에서 생성패턴을 적용하고자 할때 Factory 방식으로 시작한다. 이후에 점점 Abstract Factory, Prototype, Builder 방식으로 진화한다.
- Abstract Factory 은 종종 Factory 방식으로 구현되지만 Prototype 패턴으로 구현될 수 도 있다.
- Composite 패턴과 Decorator 패턴을 대규모로 적용하는 경우 Prototype 패턴이 큰 도움이 될 수 있다.
Prototype 패턴 | Factory Method 패턴 |
상속 X | 상속 O |
초기화 코드 O | 초기화 코드 X |