chriskelly / LifeFinances

Scripts for validating retirement plans using Monte Carlo analysis.
GNU Affero General Public License v3.0
9 stars 3 forks source link

Switch allocation method to use Strategy Design Pattern #129

Closed chriskelly closed 1 year ago

chriskelly commented 1 year ago

Define allocation strategies as separate functions and pass them into the allocation calculation.

Strategy Design Pattern Reference

Example structure:

class Strategy:
    def execute(self, *args, **kwargs):
        pass

class ConcreteStrategyA(Strategy):
    def execute(self, a, b):
        return a + b

class ConcreteStrategyB(Strategy):
    def execute(self, c, d, e):
        return c * d * e

class Context:
    def __init__(self, strategy):
        self._strategy = strategy

    def set_strategy(self, strategy):
        self._strategy = strategy

    def execute_strategy(self, *args, **kwargs):
        return self._strategy.execute(*args, **kwargs)