日期:2014-05-20  浏览次数:20798 次

如何重用实现类中的共用方法?
Java代码 
public interface CommonUploadService {  
  public void add(List excelDatalist);  
  public List sameList(List excelDatalist) throws UploadException;  
  public void deleteSame(List excelDataList);  
  public void setLog(String userName,String fileName) throws UploadException;  
}  

public interface CommonUploadService {
public void add(List excelDatalist); 
public List sameList(List excelDatalist) throws UploadException;
public void deleteSame(List excelDataList); 
public void setLog(String userName,String fileName) throws UploadException;  


Java代码 
public interface CityDayService extends CommonUploadService{  
  public List findByCityAndDate(String city,Date date);  
}  

public interface CityDayService extends CommonUploadService{
public List findByCityAndDate(String city,Date date);
}
 

Java代码 
public interface ZhbTCityDayForecastService extends CommonUploadService {  
  public List findByCityAndDate(String city, Date date);  
}  

public interface ZhbTCityDayForecastService extends CommonUploadService {
public List findByCityAndDate(String city, Date date);
} 其中,CommonUploadService 中setLog方法,在CityDayService 实现类和ZhbTCityDayForecastService 实现类是一样的.如何调整结构,能重用 setLog方法.我想继承一个BaseService,它里面写setLog方法,来达到重用.但又不知道写到哪里?



------解决方案--------------------
写个抽象类,做一个setLog方法,其他的类继承此类,就可以用 这个方法了
写一个类,写一个 静态 setLog方法,其他类,笔直调用此方法