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

Prototype design pattern #353

Closed Crossbears closed 3 years ago

Crossbears commented 3 years ago

The prototype pattern is a creative design pattern that allows you to copy existing objects without making your code depend on the classes to which they belong. You can clone the generated prototype and avoid running the initialization code repeatedly. It is used to create duplicate objects while ensuring performance. This pattern is used when creating objects directly is expensive. Simplified object creation, while avoiding the constraints of the constructor, is not restricted by the constructor directly copy the object. By trying to apply the prototype model to the simulation class.py, I hope to be able to improve the performance of the simulation runtime. Each time the user enters a set of parameters, perhaps only a single parameter change compared to the last time. Then it can replicate the results of the last simulation and only modify the corresponding parameters and don't have to do the whole thing all over again.