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
# -*- coding:utf-8 -*- | |
""" | |
@author: Diogenes Augusto Fernandes Herminio <[email protected]> | |
https://gist.github.com/420905#file_builder_python.py | |
""" | |
class Director(object): | |
def __init__(self): | |
self.buider = None |
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
# -*- coding: utf-8 -*- | |
""""http://ginstrom.com/scribbles/2008/11/06/generic-adapter-class-in-python/""" | |
import os | |
class Dog(object): | |
def __init__(self): | |
self.name = "Dog" | |
def bark(self): |
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
# http://stackoverflow.com/questions/963965/how-is-this-strategy-pattern | |
# -written-in-python-the-sample-in-wikipedia | |
""" | |
In most of other languages Strategy pattern is implemented via creating some | |
base strategy interface/abstract class and subclassing it with a number of | |
concrete strategies (as we can see at | |
http://en.wikipedia.org/wiki/Strategy_pattern), however Python supports | |
higher-order functions and allows us to have only one class and inject | |
functions into it's instances, as shown in this example. | |
""" |
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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
"""http://stackoverflow.com/questions/3118929/implementing-the-decorator-pattern-in-python""" | |
class foo_decorator(object): | |
def __init__(self, decoratee): | |
self._decoratee = decoratee | |
def f1(self): |
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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import time | |
SLEEP = 0.5 | |
# Complex Parts | |
class TC1: | |
def run(self): |
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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import random | |
import time | |
class TC: | |
def __init__(self): | |
self._tm = None | |
self._bProblem = 0 |
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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
"""http://python-3-patterns-idioms-test.readthedocs.org/en/latest/Singleton.html""" | |
class OnlyOne: | |
class __OnlyOne: | |
def __init__(self, arg): | |
self.val = arg |
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
# -*- coding utf-8 -*- | |
"""http://ginstrom.com/scribbles/2007/10/08/design-patterns-python-style/""" | |
class JapaneseGetter: | |
"""A simple localizer a la gettext""" | |
def __init__(self): | |
self.trans = dict(dog="犬", cat="猫") | |
def get(self, msgid): |
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
# -*- coding: utf-8 -*- | |
"""http://code.activestate.com/recipes/131499-observer-pattern/""" | |
class Subject(object): | |
def __init__(self): | |
self._observers = [] | |
def attach(self, observer): | |
if not observer in self._observers: |
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
# -*- coding: utf-8 -*- | |
class Handler: | |
def successor(self, successor): | |
self.successor = successor | |
class ConcreteHandler1(Handler): | |
def handle(self, request): |