paulvangentcom / python_corona_simulation

An agent-based simulation of corona and other viruses in python
GNU General Public License v3.0
292 stars 76 forks source link

Aggregate design on population.py #21

Closed alfredmjz closed 3 years ago

alfredmjz commented 3 years ago

Applying Aggregate Design Pattern to population.py Module

Introduction

I am a third-year computer science student. A part of the learning process for the Software Design course, we have to contribute to one of many given options of open source projects. For this particular project, we have to apply an aggregate design pattern to the chosen project publicly by making two pull requests.

Abstract

The code in population.py was unordered and unstructured, potentially losing unnecessary resources on reading and understanding the code. Mainly, some methods were given a class while others didn't have any. This is considered a bad practice in software design because it may lead to complexity, specifically low clarity on which parts of the code must be modified to make the improvement or future debugging. To solve this, I applied the aggregate design pattern by encapsulating the population class to emphasize the relation between the classes and methods such as:

  1. Population – the root aggregate and contains all aggregated classes and methods
  2. Population_setup – contains methods that help initialize the population parameters for the simulation
  3. Population_trackers – contains methods to track population parameters (Already implemented)
  4. Population_data – contains methods that save population and simulation data to disk

Why aggregation?

As mentioned before, population.py was unordered and unstructured, we applied aggregation to solve this problem. Through aggregation, code is modularized into shorter and in-relational contexts with other aggregated methods, thus, reduces complexity and increase readability and understanding. Additionally, creating a separate class for the different functions of the population decreases the magnitude of change amplification and eases imports of corresponding methods in other files. Everything that is related to the population module is in one place, separated by functionality. Further implementation can be easily added correspondingly.

Changes made