design-patterns/behavioral/template/main.py
2020-10-09 12:25:31 +02:00

21 lines
734 B
Python

from behavioral.template.abstract_class import AbstractClass
from behavioral.template.concrete_classes import ConcreteClass1, ConcreteClass2
def client_code(abstract_class: AbstractClass) -> None:
"""
The client code calls the template method to execute the algorithm. Client
code does not have to know the concrete class of an object it works with, as
long as it works with objects through the interface of their base class.
"""
abstract_class.template_method()
if __name__ == "__main__":
print("Same client code can work with different subclasses:")
client_code(ConcreteClass1())
print("")
print("Same client code can work with different subclasses:")
client_code(ConcreteClass2())