我正在自学创建可以在外部覆盖的类,基本上是为了模拟一个我只提供接口实现的框架。我注意到 hadoop 实际上使用:
job.setMapperClass(FrameworkObject.class);
在驱动程序类中执行此操作,是否可以简单地更改下面的代码来执行此操作?
//----- locked framwork interface...
public interface FrameworkInterface {
public void PrintStuff();
}
//----- locked framwork factory class...
public class FrameworkFactory {
public static void doStuff(FrameworkInterface fi){
fi.PrintStuff();
}
}
//------------ my code that hooks into a framework...
public class FrameworkObject implements FrameworkInterface {
public FrameworkObject() {
// TODO Auto-generated constructor stub
}
@Override
public void PrintStuff() {
System.out.println("the implemented method...");
}
}
//------------ the framework driver I want to change
public class FrameworkDriver {
public static void main(String[] args){
FrameworkFactory.doStuff(new FrameworkObject()); // explicit ref to object
}
}