We observe that in the Sim class, we have a number of functions to initialize fields—examples include init_results, init_people, init_interventions, init_analyzers, init_variants and init_immunity. These functions utilize modules outside of the Sim class, which are imported and called with the result of initializing fields of the current simulation. For example, to create the interventions field in init_interventions, functions of the interventions.py module are called.
Unlike the other init functions, we notice that init_results directly initializes the results field of the Sim class, without utilizing an external module for generating the results (like how interventions.py was responsible for generating interventions). We also notice, however, that init_results utilizes an external module for a single result in the init_res function, referencing the Result class of base.py. This is an area where the aggregate domain pattern can be applied, with a Results aggregate to coincide with the Result class.
Description of Changes
The class Results thus resides in base.py alongside the Result class. This includes the initialization of results, creating the aggregate root results utilizing the aforementioned init_res function. As an aggregate, Results has multiple Result instances, but these Result instances’ lifecycles are not tied to that of Results. The init_results method is now simplified to accessing the simulation results through the root of the Results aggregate.
Please note: this PR is part of a school project.
Why?
We observe that in the
Sim
class, we have a number of functions to initialize fields—examples includeinit_results
,init_people
,init_interventions
,init_analyzers
,init_variants
andinit_immunity
. These functions utilize modules outside of theSim
class, which are imported and called with the result of initializing fields of the current simulation. For example, to create the interventions field ininit_interventions
, functions of theinterventions.py
module are called.Unlike the other
init
functions, we notice thatinit_results
directly initializes theresults
field of theSim
class, without utilizing an external module for generating the results (like howinterventions.py
was responsible for generating interventions). We also notice, however, thatinit_results
utilizes an external module for a single result in theinit_res
function, referencing theResult
class ofbase.py
. This is an area where the aggregate domain pattern can be applied, with aResults
aggregate to coincide with theResult
class.Description of Changes
The class
Results
thus resides inbase.py
alongside the Result class. This includes the initialization of results, creating the aggregate rootresults
utilizing the aforementionedinit_res
function. As an aggregate,Results
has multipleResult
instances, but theseResult
instances’ lifecycles are not tied to that ofResults
. Theinit_results
method is now simplified to accessing the simulation results through the root of theResults
aggregate.