InstituteforDiseaseModeling / covasim

COVID-19 Agent-based Simulator (Covasim): a model for exploring coronavirus dynamics and interventions
https://covasim.org
MIT License
250 stars 223 forks source link

apply aggregation in sim.py #340

Closed shazonglin closed 2 years ago

shazonglin commented 3 years ago

Applying Aggregate Design Pattern to sim.py

Background I made this change to apply the aggerate pattern in the open-source project we chose in the lab. And the goal of this lab is to find the place that can apply aggeration. Therefore we are asked to make 2 pull request

Abstract When I design the domain diagram for this project. I have the sim domain in my design. But the in sim.py contained many functions like initializing, compute, display, etc. However, the functions were not grouped well together. This creates obscurity in the code and makes it hard to read. Hence, I created three new classes in sim as root aggregate which are set_up, compute and display.

Explanation The sim module contained many functions that operate on certain data types, which were not aggregated together. For example, all the init_* functions are used to initialize the objects. These functions help construct data on states, so we can aggregate them into sim class to make the code easier to read and understand.

cliffckerr commented 2 years ago

Thanks for the PR -- we're not considering major architectural changes currently, but we appreciate the contribution to open-source software!