InstituteforDiseaseModeling / covasim

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

Apply aggregation in population.py #334

Closed shazonglin closed 3 years ago

shazonglin commented 3 years ago

Applying Aggregate Design Pattern to population.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 population domain in my design. But the in population.py only contained several functions like make_people, make_randpop, and functions to deal with contacts, etc. However, the functions were not grouped well together. This creates obscurity in the code and makes it hard to read. Hence, I created two new classes population as root aggregate and contact to aggregate their respective operations.

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