mirror of
https://github.com/rjNemo/design-patterns
synced 2026-06-06 02:26:40 +00:00
43 lines
1.5 KiB
Python
43 lines
1.5 KiB
Python
"""Concrete Products are created by corresponding Concrete Factories."""
|
|
|
|
from AbstractProductA import AbstractProductA
|
|
from AbstractProductB import AbstractProductB
|
|
|
|
|
|
class ConcreteProductA1(AbstractProductA):
|
|
def useful_function_a(self) -> str:
|
|
return "The result of the product A1."
|
|
|
|
|
|
class ConcreteProductA2(AbstractProductA):
|
|
def useful_function_a(self) -> str:
|
|
return "The result of the product A2."
|
|
|
|
|
|
class ConcreteProductB1(AbstractProductB):
|
|
|
|
def useful_function_b(self) -> str:
|
|
return "The result of the product B1."
|
|
|
|
def another_useful_function_b(self, collaborator: AbstractProductA) -> str:
|
|
"""
|
|
The variant, Product B1, is only able to work correctly with the variant,
|
|
Product A1. Nevertheless, it accepts any instance of AbstractProductA as an
|
|
argument.
|
|
"""
|
|
result = collaborator.useful_function_a()
|
|
return f"The result of the B1 collaborating with the ({result})"
|
|
|
|
|
|
class ConcreteProductB2(AbstractProductB):
|
|
def useful_function_b(self) -> str:
|
|
return "The result of the product B2."
|
|
|
|
def another_useful_function_b(self, collaborator: AbstractProductA):
|
|
"""
|
|
The variant, Product B2, is only able to work correctly with the
|
|
variant, Product A2. Nevertheless, it accepts any instance of
|
|
AbstractProductA as an argument.
|
|
"""
|
|
result = collaborator.useful_function_a()
|
|
return f"The result of the B2 collaborating with the ({result})"
|