mirror of
https://github.com/rjNemo/design-patterns
synced 2026-06-06 02:26:40 +00:00
21 lines
734 B
Python
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())
|