------------------------------ 适配器模式(adapter) -------------------------------

  (1)适配器模式的意图是将一个已存在的类/接口进行复用,将其转换/具体化成客户希望的另外的一个类/接口。

  (2)如何实例复用:

  将要进行复用的类,放到目标类的构造方法中,进行实例化,然后在目标类的相应方法中,进行调用,修改原来方法中的参数,或添加相应的逻辑。即复用了已有类的原来方法。

  要被复用的类:

public class Adaptee{
public long getPower(long base,long exp){
long result=1;
for(int i=0;i<exp;i++)
result*=base;
return result;
}
}

  目标类:--也可直接实现,不用接口。

public interface Target{
public long get2Power(long exp);
}
public class Adapter implements Target{
private Adaptee pt;
public Adapter(){
pt = new Adaptee();
}
public long get2Power(long exp){
return pt.getPower(2,exp);   ---修改原来方法中的参数,
}
}

  (3)又如:在SCM中添加的方法:

  已有接口:

  public boolean updateRecordStates(Double recordId,Double tableNameMapping,int state,boolean

  subRecordUpdate) throws RemoteException;

  已有实现类:

public boolean updateRecordStates(Double recordId,Double tableNameMapping,int state,boolean
subRecordUpdate) throws RemoteException
{
return moveTable.updateRecordStates(recordId,tableNameMapping,state,subRecordUpdate);
}

  若采用适配器模式:

  接口:

  public boolean updateStatesAdapterForSelfPanel(Double recordId,Double tableNameMapping,int state)

  throws RemoteException;

  实现类:

public boolean updateStatesAdapterForSelfPanel(Double recordId,Double tableNameMapping,int state)
throws RemoteException
{
return this.updateRecordStates(recordId,tableNameMapping,state,false);
}