Created
June 10, 2017 17:21
-
-
Save matthewjackowski/21a40c866191666dfc16208c648ec773 to your computer and use it in GitHub Desktop.
Pythonic Facade
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
# ChangeInterface/Facade.py | |
class A: | |
def __init__(self, x): pass | |
class B: | |
def __init__(self, x): pass | |
class C: | |
def __init__(self, x): pass | |
# Other classes that aren't exposed by the | |
# facade go here ... | |
class Facade: | |
def makeA(x): return A(x) | |
makeA = staticmethod(makeA) | |
def makeB(x): return B(x) | |
makeB = staticmethod(makeB) | |
def makeC(x): return C(x) | |
makeC = staticmethod(makeC) | |
# The client programmer gets the objects | |
# by calling the static methods: | |
a = Facade.makeA(1); | |
b = Facade.makeB(1); | |
c = Facade.makeC(1.0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Credit: Bruce Eckel and Friends
http://python-3-patterns-idioms-test.readthedocs.io/en/latest/ChangeInterface.html