建造者模式,实例的参数初始化由建造类方法完成。
class Instance(object):
def __init__(self, builder):
super().__init__()
self.url = builder.url()
self.proxy = builder.proxy()
class Builder(object):
def __init__(self):
pass
def url(self):
return "url"
def proxy(self):
return "proxy"
def main():
builder = Builder()
instance = Instance(builder)
if __name__ == '__main__':
main()