Last active
August 29, 2015 14:08
-
-
Save mistermocha/0f7eaf69f02afb6cfb05 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BigStorageClass(object): | |
'''Class that will represent a large data blob that contains lots of smaller child objects''' | |
def lookup_something(self, **kwargs): | |
some_data = self.do_something_with(kwargs) | |
return some_data | |
class SmallChildObject(object): | |
'''Instantiation of this class needs to look up something in an instance of the BigStorageClass. Clearly, | |
I don't want to make BigStorageClass a child of SmallChildObject. Is there a way to pass in the *name* of | |
the BigStorageClass instance as a string and get the instance?''' | |
def __init__(self, ref_to_storage) | |
self.look_in_storage_class(ref_to_storage) | |
def look_in_storage_class(self, classname): | |
storage_class = get_instance_by(classname) | |
return storage_class(...) | |
bigdata = BigStorageClass(...) | |
''' do some stuff to put lots of data in bigdata ''' | |
smallobj = SmallChildObject(self, 'bigdata') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment