design-patterns/behavioral/strategy/main.py
Ruidy 03cb570b65
Strategy (#22)
* add documentation

* add code example
2020-10-09 12:01:22 +02:00

15 lines
576 B
Python

"""
The client code picks a concrete strategy and passes it to the context.
The client should be aware of the differences between strategies in order to make the right choice.
"""
from behavioral.strategy.concrete_strategies import ConcreteStrategyA, ConcreteStrategyB
from behavioral.strategy.context import Context
context = Context(ConcreteStrategyA())
print("Client: Strategy is set to normal sorting.")
context.do_some_business_logic()
print()
print("Client: Strategy is set to reverse sorting.")
context.strategy = ConcreteStrategyB()
context.do_some_business_logic()