I am building a simulator and I have many classes in different Python files. Currently, I created a dictionary in one of my classes (Building
class), and then I am calling it from other classes to update or use the information stored inside it. I am storing my agents in that dictionary. The Building
class has some other variables and methods. Since I only need the dictionary inside it for most of my classes, I don't want to inherit or use it as a composite. This might be a good way but I am suspicious about its memory consumption and not sure to use it. So, I am asking is it a good way to circulate a dictionary to keep track of my agents? What is a good way to do this? An example code will be much appreciated.
My idea so far:
# in Building.py
class Building(object):
# This class includes all of the facilities in the building.
# It also includes several dictionaries to keep track of all of the facilities and agents.
residentsDic = {}
def __init__(self, A, B):
self.A = A
self.B = B
# in ResidentArrival.py
import Building
class ResidentArrival(object):
# This generates resident agents according to a timetable.
# I did't write the whole class
def __init__(self, C, D):
self.A = A
self.B = B
def addResident(self, resident):
Building.residentsDic[resident].arrivalTime = time.now()
# in Resident.py
class Resident:
# Resident class
blaBla