|
|
|
banq上的adapter中最后关于two-way adapter中的程序是这样的 public class PegAdapter implements IRoundPeg,ISquarePeg{
private RoundPeg roundPeg; private SquarePeg squarePeg;
// 构造方法 public PegAdapter(RoundPeg peg){this.roundPeg=peg;} // 构造方法 public PegAdapter(SquarePeg peg)(this.squarePeg=peg;)
public void insert(String str){ roundPeg.insertIntoHole(str);}
}
我觉得好象少了点什么,这个adapter好象没有反应出squarePeg的功能吧?
|
|
|
|
|
|
Re: 关于网站上的Adapter范例
|
2003年05月19日 17:49
|
|
|
没写使用squarePeg的那一句。
这东东就象调鸡尾酒,这个模式使用很多,几乎稍微复杂一点都要用
|
|
|
|
|
|
Re: 关于网站上的Adapter范例
|
2003年05月26日 12:02
|
|
|
我觉得这个解释好象和把GOF中的原意说的不太一样, GOF首先讨论的是Adaptee和targetInterface的适配程度, 它们可能相差很远也可能相差不远,如果相差很远的作为例子会让一些人产生误解
|
|
|
|