Last active
July 25, 2018 16:39
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
# Framework internal | |
def MetaIoC(name, bases, namespace): | |
cls = type("IoC{}".format(name), tuple(), namespace) | |
return type(name, bases + (cls,), {}) | |
# Entities level | |
class Entity: | |
def _lower_level_meth(self): | |
raise NotImplementedError | |
@property | |
def entity_prop(self): | |
return super(Entity, self)._lower_level_meth() | |
# Adapters level | |
class ImplementedEntity(Entity, metaclass=MetaIoC): | |
__private = 'private attribute value' | |
def __init__(self, pub_attr): | |
self.pub_attr = pub_attr | |
def _lower_level_meth(self): | |
print('{}\n{}'.format(self.pub_attr, self.__private)) | |
# Infrastructure level | |
if __name__ == '__main__': | |
ENTITY = ImplementedEntity('public attribute value') | |
ENTITY.entity_prop |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment