Abstract Factory is a creational design pattern that lets you produce families of related objects without specifying their concrete classes.
가구점 시뮬레이터(furniture shop simulator
)를 만드는데 다음과 같은 클래스로 구성되어 있다.
1. 관련 제품군: Chair
+ Sofa
+ CoffeeTable
.
2. 카테고리 : Modern
+ Victorian
+ ArtDeco
.
동일한 카테고리의 furniture object
를 생성하여 매치시킬 수 있는 방법이 필요하다. (만약 고객이 가구를 추가 주문했는데 다른 카테고리의 제품이 배송되면 만족스럽지 못할 것이다.)
뿐만아니라, 새로운 제품이나 카테고리가 추가될 때 마다 기존의 코드를 수정하는 것을 원하진 않을 것이다.
각 제품군(Chair
, Sofa
, CoffeeTable
)에 대한 인터페이스를 명시적으로 선언하고 모든 제품(all variants of products
)은 인터페이스를 상속 받는다.
제품별 생성 함수(createChair
, createSofa
and createCoffeeTable
)가 선언되어 있는 Abstract Factory 인터페이스를 선언한다.
카테고리별로 AbstractFactory를 상속받고 있는 Factory클래스를 만들어준다.
(참고로 ModernFurnitureFactory
는 ModernChair
, ModernSofa
and ModernCoffeeTable
객체만 만들 수 있다.)
https://woovictory.github.io/2019/02/07/Design-Pattern-Factory-Pattern/
https://refactoring.guru/design-patterns/abstract-factory