|
|
|
关于adapter模式.
|
2002年10月22日 15:13
|
|
|
标签列表
|
|
banq大作中关于adapter的程序不太理解.按我的理解adapter应该提供几个接口的方法.可是文章中最终那个adapter只能打圆洞了.是否应改成下面这样; public class PegAdapter extends SquarePeg{
private RoundPeg roundPeg;
public PegAdapter(RoundPeg peg){this.roundPeg=peg;} public void insert(String str){super.insert(str)} public void insertIntoHole(String str){ roundPeg.insertIntoHole(str);} } 这样才能提供打洞的两种方法.请指教.
|
|
|
|
|
|
Re: 关于adapter模式.
|
2002年10月22日 15:27
|
|
|
另外,我已经可以用roundpeg.insertintohole()打圆洞了,虽然我们不知道其源代码,也没什么关系啊,我为什么要这个adapter类呢?不理解. new RoundPeg().insertintohole("xxx"); new SqarePeg().insert("xxx"); 不是蛮好的吗?这个模式什么的真是太难了,请指教.
|
|
|
|
|
|
Re: 关于adapter模式.
|
2002年10月22日 17:56
|
|
|
为什么需要一个adapter类?
是因为有可能我们要对RoundPeg的insertintohole方法进行改动,但是我们又不愿意更改RoundPeg的代码,或者我们根本不可能更改(没有源代码等),所以要重构一个adapter类。
|
|
|
|
|
|
Re: 关于adapter模式.
|
2002年10月23日 13:22
|
|
|
谢谢.可是你还没有回答我第一个问题.请教. 这几天才开始对板主的大作,多多帮忙.
|
|
|
|
|
|
Re: 关于adapter模式.
|
2002年10月23日 14:02
|
|
|
|
第一个问题,你写的代码也可以,取决于你具体应用,我那里的代码只是将特征代码写出来,
|
|
|
|