After reading thousands of posts about how bad Global variables are, I got back to where I started from.
Here is a contrived example which I hope can explain my situation and my question:
TCity
: has a list of BuildingsTBuilding
: Is part of a city | has exact 2 garagesTGarage
: Is part of a Building | has a List of CarsTCar
: Is part of a Garage | Has a Linked List of CarsTCar1
,TCar2
,TCar3
: Is Descendant of TCar
i have an instance of TBuilding which needs to be accessed by every single other Class.
The TBuilding Class needs to be accessed by the Cars.
Should I make a global variable for the TCity and TBuilding instance, or is there anything else I can do ?
I tried to merge the TCity, TBuilding and TGarage classes, but that gives me headaches everytime I try.
Could some experienced people here lead me in the right direction?
I was about to create a Container Class, to share the needed instances between units. But after reading lots of posts, I wasn't sure that this was the correct way of dealing with this problem.
What about resourcestring
s. Should I create a Container with reourcestrings which are shared amongst Classes. For Example if I have about 20 classes where I need the same string every time. The string needs to be translated, so I make a resourcestring
out of it. Where do I collect such data?