I have 3 modules: A, B, C
A contains a set of classes that B has fetchers for.
B contains a bunch of singletons that just deal with caching created objects and providing them when requested. Essentially just fetchers.
C is a list of functions that requires instances of A.
The operation that I need to do is something along the lines of:
C::SomeFunc():
B.getInstance("instance ID")
B::getInstance(someID: str) -> A:
-look at cache, which is either [] or {}
-if it is in cache, return that, else do: A(someID)
My question is, how would you pass around the instances of these modules around? This question is primarily motivated by my lack of understanding of Python's memory allocation system.
I could do something along the lines of constructor-based dependency injection to get an instance of A,B,C where they need to go, and then have some "master/god/controller" object that just passes things where they need to go -
eg:
class god(object):
def __init__(self):
a = A()
b = B()
c = C(b)
.....
.....
class C(object):
def __init__(self, B_instance):
self.B = B_instance
def SomeFunc(self, instanceID):
self.B.getInstance(instanceID)
but this seems like a hack.
Any suggestions?
Thanks!