设计模式学习笔记:看着挺像的Adpater Bridge

适配器模式定义(个人理解:只是个套子)

设计模式学习笔记:看着挺像的Adpater Bridge

 Convert the interface of a class into another interface clients excpet. Adapter lets classes work together that couldn't otherwise becase of incompatible interfaces.

 

模式理解:

看到第一眼的时候,我就觉得坑爹啊,怎么又和bridge长的那么像啊。再一转念,其实它们之间有巨大的不同:从实际编码来说Adaptee基本上就是现成的,而Target也很高概率是完成的。

而Adpater目的是为了让Target和Adaptee一起工作。所以Adapter会去继承或者实现Target,用Target的壳做Adaptee的事情。

 

模式变种:双向适配

看到有的资料说有一种变体,叫做双向适配。

也就是多重继承。对java来说就是同时实现2个接口或者继承一个类再另外实现一个接口。

我想这种情况的出现,只可能在一个系统,而且设计失误了,作为一种补救的措施...囧

 

 

转载于:https://www.cnblogs.com/mattmonkey/archive/2011/06/12/2301578.html