Adapter形式(Object Adapter)
Adapter模式(Object Adapter)Adapter模式使原本由于接口不兼容而不能在一起工作的类可以一起工作,即为一个
Adapter模式(Object Adapter)
Adapter模式使原本由于接口不兼容而不能在一起工作的类可以一起工作,即为一个内容合适但接口不匹配的对象创建一个新的接口.Adapter模式让现存的对象适应新的类结构,而不受他们的接口限制.
例如现在,我们有一个球袋类BasketballBag负责完成装入篮球。
class BallBag extends BasketballBag{ FootballBag fb; public BallBag(FootballBag fb) { this.fb = fb; } public void putBasketball() //It will be better if the name is "putBall" { fb.putFootball(); }}
upwards is my understanding. I'm beginner of pattern. Talk about it together.
2 楼 Ozone 2008-05-05 Ok。No problem,next demo is class adapter. 3 楼 duanbo 2008-05-05 Ozone 写道Ok。No problem,next demo is class adapter.
pls see my update. 4 楼 Ozone 2008-05-05 In your opinion bbag don't equal to fb ? I think ,BallBag is a help object,which have equal BallBag with BasketballBag. 5 楼 liuleigang 2008-11-20 楼主举的例子能测试通过?在BallBag的putBaseketBall方法中要调用putFootball。 6 楼 qingfengjushi1 2008-11-21 LZ的例子测试过吗?