lundi 21 janvier 2019

pattern for keeping data produced by many instances of a class

My Python program has a main.py module which creates many board objects from the Board class. The Board class uses the Brain class to decide what can happen on the board. The Brain class uses the Data class to help it make decisions.

The problem I'm having is the every time any Board object has the Brain do something, new information has to be added to the same Python dictionary in the Data class. I'm afraid to say it, but I really do think the spirit of this dictionary in the Data class is that it needs to be "global". What is the correct pattern so all instances can write to the same dictionary? Should I even be using a Data class to hold the dictionary?

Aucun commentaire:

Enregistrer un commentaire