mirror of
https://github.com/rjNemo/design-patterns
synced 2026-06-06 02:26:40 +00:00
* doc: create package & update general TOCs * doc: add documentation * add code example * reformat using black
34 lines
1 KiB
Python
34 lines
1 KiB
Python
from creational.abstract_factory.AbstractFactory import AbstractFactory
|
|
from creational.abstract_factory.products import (
|
|
ConcreteProductA1,
|
|
ConcreteProductB1,
|
|
ConcreteProductA2,
|
|
ConcreteProductB2,
|
|
)
|
|
|
|
|
|
class ConcreteFactory1(AbstractFactory):
|
|
"""
|
|
Concrete Factories produce a family of products that belong to a single
|
|
variant. The factory guarantees that resulting products are compatible.
|
|
Note that signatures of the Concrete Factory's methods return an abstract
|
|
product, while inside the method a concrete product is instantiated.
|
|
"""
|
|
|
|
def create_product_a(self) -> ConcreteProductA1:
|
|
return ConcreteProductA1()
|
|
|
|
def create_product_b(self) -> ConcreteProductB1:
|
|
return ConcreteProductB1()
|
|
|
|
|
|
class ConcreteFactory2(AbstractFactory):
|
|
"""
|
|
Each Concrete Factory has a corresponding product variant.
|
|
"""
|
|
|
|
def create_product_a(self) -> ConcreteProductA2:
|
|
return ConcreteProductA2()
|
|
|
|
def create_product_b(self) -> ConcreteProductB2:
|
|
return ConcreteProductB2()
|