请大家看以下的代码,A部分是接口实现,B部分是普通类实现,请问,如果用A部分实现,好处在哪里??????? -----------------------------A------------------------------------------- //生物接口 interface Biology{ abstract void study();//是否会学习 } //人会学习JAVA class NormalMan implements Biology{ public void study(){ System.out.println("man study java"); } } //马不会学JAVA class NormalHorse implements Biology{ public void study(){ System.out.println("horse not study java"); } } ------------------------------B---------------------------------------------- publec class Biology{ public Biology(String type) { study(type) } public void study(String type){ if ("Man".equals(type)) System.out.println("man study java"); if ("Horse".equals(type)) System.out.println("horse not study java"); } }
interface iTable Class TableA implements iTableClass TableB implements iTable在做一个工厂类,由工厂类factory的getTable来实现实例化那个类。public iTable getTable(){}
-----------------------------A-------------------------------------------
//生物接口
interface Biology{
abstract void study();//是否会学习
}
//人会学习JAVA
class NormalMan implements Biology{
public void study(){
System.out.println("man study java");
}
}
//马不会学JAVA
class NormalHorse implements Biology{
public void study(){
System.out.println("horse not study java");
}
}
------------------------------B----------------------------------------------
publec class Biology{
public Biology(String type) {
study(type)
}
public void study(String type){
if ("Man".equals(type))
System.out.println("man study java");
if ("Horse".equals(type))
System.out.println("horse not study java");
}
}
隐藏底层数据库操作