橋接模式,一個類包含不同種類屬性,將不同種類的屬性分別轉(zhuǎn)為不同的類。
class Type(object):
def __init__(self, type_):
self.type = type_
def set_type(self, type_):
self.type = type_
class Color(object):
def __init__(self, color):
self.color = color
def set_color(self, color):
self.color = color
class Object(object):
def __init__(self, color, type_):
self.color = color
self.type = type_
def do_work(self):
print(self.color.color, self.type.type)
def main():
obj = Object(Color("Red"), Type("Normal"))
obj.do_work()
if __name__ == '__main__':
main()