Skip to content
cheyiliu edited this page Jul 25, 2016 · 8 revisions

design pattern

creation

  • 本来创建一个对象很简单 new 调用构造方法就好了, 干嘛需要builder呢? 说明这个类的内部属性比较复杂, 初始数据全部放到构成函数又很让人晕(比如,参数类型相同 参数又太多) 各种set方法又不能很好的配合(属性可能有依赖关系等)。。。 这时候就可以考虑用builder了。 类似导购将消费者直接带入主题,一步一步的帮你完成购买。我们通过builder,调用builder的方法一步步的实现构建。

structure

The proxy design pattern allows you to provide an interface to other objects by creating a wrapper class as the proxy. The wrapper class, which is the proxy, can add additional functionality to the object of interest without changing the object's code.

Proxy vs. Adapter

The Proxy changes the behavior of the Service, but preserves its interface. The Adapter changes the interface of the Service, but preserves it behavior. A Client can use the Proxy or the Service Entity in the same way. A Client designed to use the Adapter would not be able to use the Service Entity without it. The Proxy can be cast to the interface of the Service. The Adapter can be cast to the interface the Client expects.

Adapter vs. Facade

The Adapter is used to preserve existing polymorphism. In other words, the interface you are adapting to probably already exists, and is probably already committed to. The Facade provides a more idealized interface, but it can be developed incrementally as new needs of the subsystem are discovered. Adapters are usually small, and therefore do not raise performance concerns, typically. Facades tend to be large, and therefore it may be useful to make sure they are re-entrant (so as to avoid the need for multiple instances). The "Adaptee" is probably fine as it is, you're using the Adapter because you've committed to a different interface. The "Facadee" is probably not fine as it is, and you are communicating this to other developers by using the term "Facade".

Proxy vs. Facade

Proxies are optional, Facades typically are not. The purpose of the Proxy is to add behavior. The purpose of the Facade is to simplify, which may actually involve removing behavior


### behavior

# ref
* https://github.com/cheyiliu/test4java/tree/master/src/test/design/pattern
Clone this wiki locally