Bridge设计模式,将一个复杂类分红能够单独开发的部分。分红的两个部分,abstraction,implementation。字面上是抽象和实现,但不一样于抽象方法及其实现。下面摘录Wiki的两句话。设计模式
decouple an abstraction from its implementation so that the two can vary independently设计
这句话,讲的是这个模式的定义。Bridge将abstraction从implementation中抽取出来,让abstraction和implementation这两个部分能够单独的变化。code
The class itself can be thought of as the abstraction and what the class can do as the implementation.blog
这句话太精髓了!复杂类究竟该怎么分红两个部分?这句话给出了回答。一部分是咱们看这个类应该是怎么样子的,另外一部分是它能够作什么。ip
下面改一改来自[1]的回答。开发
When:get
----Animal---- / \ Dog Cat / \ / \ RunDog SleepDog RunDog SleepDog
Refactor to:博客
----Animal---- Behavior / \ / \ Dog(Behavior) Cat(Behavior) Run Sleep
总结it
这篇博客太水了。io