Created
September 11, 2013 16:50
-
-
Save romulojales/6526462 to your computer and use it in GitHub Desktop.
Exemplo do Design Pattern Bridge
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
class NegocioAbstrato(object): | |
def funcao_abs(self, arg): | |
return arg | |
def funcao_repassada_ao_bridge(self, arg): | |
ponte = self.__get_ponte(arg) | |
return ponte.funcao_assumida(arg) | |
def __get_ponte(self, arg): | |
if type(arg) == str: | |
return ImplementadorSTR() | |
elif type(arg) == int: | |
return ImplementadorINT() | |
class ClasseCliente(NegocioAbstrato): | |
def minha_funcao(self): | |
return "Oi sou funcao do cliente" | |
class ImplementadorAbstrato(object): | |
def funcao_assumida(self, arg): | |
raise NotImplemented | |
class ImplementadorSTR(ImplementadorAbstrato): | |
def funcao_assumida(self, arg): | |
return "oi sou uma string: " + arg | |
class ImplementadorINT(ImplementadorAbstrato): | |
def funcao_assumida(self, arg): | |
return "oi sou um inteiro: " + str(arg) | |
c = ClasseCliente() | |
print c.minha_funcao() | |
print c.funcao_abs(123) | |
print c.funcao_repassada_ao_bridge(1) | |
print c.funcao_repassada_ao_bridge("1") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment