Created
January 25, 2017 20:59
-
-
Save typemytype/40f85e9cf1ecd0a85a59645a29f4a6b1 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 Implementation(object): | |
| def __init__(self, tag): | |
| self._tag = tag | |
| self._instance = None | |
| def __getattr__(self, attr): | |
| attr = "_%s_%s" % (self._tag, attr) | |
| return getattr(self._instance, attr) | |
| def __get__(self, instance, obj): | |
| self._instance = instance | |
| return self | |
| class BaseContour(object): | |
| def aMethod(self, point): | |
| return "BaseContour aMethod", self, point | |
| class BetaContour(BaseContour): | |
| beta = Implementation("beta") | |
| def _beta_aMethod(self, point): | |
| return "BetaContour aMethod", self, point | |
| def _beta_moreMethods(self, foo): | |
| return "BetaContour moreMethods", self, foo | |
| class Contour(BetaContour): | |
| roboFont = Implementation("roboFont") | |
| def _roboFont_aMethod(self, point, test): | |
| return "Contour aMethod", self, point, test | |
| def _beta_testing(self, someThing): | |
| return "Contour testing", self, someThing | |
| c = Contour() | |
| print c.aMethod("a") | |
| print c.roboFont.aMethod("a", "b") | |
| print c.beta.moreMethods("bar") | |
| print c.beta.testing("m") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment