桥接模式,一个类包含不同种类属性,将不同种类的属性分别转为不同的类。
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()
网友评论