ChrisCScott / forecaster

A personal finances forecasting tool for Canadian retirement planning
Other
1 stars 2 forks source link

Enable communication between SubForecast objects and between years #54

Closed ChrisCScott closed 5 years ago

ChrisCScott commented 5 years ago

Each SubForecast object may need to obtain values calculated by other SubForecast objects. For example, IncomeForecast may need to access the total_tax_withheld and total_tax_owed attributes of TaxForecast for the previous year.

In general, each SubForecast may need to access a value (a) for the current year from any SubForecast preceding it in the model or (b) for an earlier year from any SubForecast. Earlier planning only accounted for (a) (see #40).

We can simplify this considerably by simply passing each SubForecast a reference to either the parent Forecast or to all of its sibling SubForecast objects. The former approach seems like the most straightforward, though it makes the encapsulation of each SubForecast somewhat less strict.

ChrisCScott commented 5 years ago

We're opting for stronger encapsulation. SubForecast instances do not have access to each others' state. They may communicate only by mutating available, which is passed between them in the order defined by Forecast.

A working implementation of Forecast and SubForecast based on this model is provided in the develop branch via the above commit.