Skip to content

Instantly share code, notes, and snippets.

@matthewjackowski
Created June 10, 2017 17:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matthewjackowski/21a40c866191666dfc16208c648ec773 to your computer and use it in GitHub Desktop.
Save matthewjackowski/21a40c866191666dfc16208c648ec773 to your computer and use it in GitHub Desktop.
Pythonic Facade
# 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);
@matthewjackowski
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment