# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # SPDX-License-Identifier: MIT-0 from __future__ import annotations from typing import List from table_definition import TableDefinition from target_strategy import TargetStrategy class Context: """ The Context defines the interface of interest to clients. """ def __init__(self, strategy: TargetStrategy) -> None: """ Usually, the Context accepts a strategy through the constructor, but also provides a setter to change it at runtime. """ self._strategy = strategy @property def strategy(self) -> TargetStrategy: """ The Context maintains a reference to one of the Strategy objects. The Context does not know the concrete class of a strategy. It should work with all strategies via the Strategy interface. """ return self._strategy @strategy.setter def strategy(self, strategy: TargetStrategy) -> None: """ Usually, the Context allows replacing a Strategy object at runtime. """ self._strategy = strategy def synchronize(self, table_definitions: List[TableDefinition]) -> None: """ The Context delegates some work to the Strategy object instead of implementing multiple versions of the algorithm on its own. """ result = self._strategy.synchronize(table_definitions=table_definitions)