package zhu;
public class test1006 {
public static void main(String[] args) {
BaseService user=new UserService();
user.setISave(new FileSave());
user.add("test");
}
}
interface ISave{
public void save(String data);
}
class FileSave implements ISave{
public void save(String data) {
System.out.println("文件"+data);
}
}
class NetSave implements ISave{
public void save(String data) {
System.out.println("网络"+data);
}
}
abstract class BaseService{
private ISave iSave;
public void setISave(ISave iSave) {
this.iSave=iSave;
}
public void add(String data) {
System.out.println("方法1");
iSave.save(data);
System.out.println("saved");
}
}
class UserService extends BaseService{
}