interface Service{
void method1();
void method2();
} interface ServiceFactory{
Service getService(); getService方法返回Service接口是什么意思
} class Implementation implements Service{
public void method1(){print("this is menthod1");}
public void method2(){print("this is menthod2");}
} 这个能看懂
class ImplementationFactory implements SerivceFactory{
public Service getService(){
return new Implementation();
}这个类继承SerivceFactory接口,为什么返回Implementation()这个类;
}
void method1();
void method2();
} interface ServiceFactory{
Service getService(); getService方法返回Service接口是什么意思
} class Implementation implements Service{
public void method1(){print("this is menthod1");}
public void method2(){print("this is menthod2");}
} 这个能看懂
class ImplementationFactory implements SerivceFactory{
public Service getService(){
return new Implementation();
}这个类继承SerivceFactory接口,为什么返回Implementation()这个类;
}
Service getService(); getService方法返回Service接口是什么意思
}
这个接口定义一getService();反回类型是Service.也就是说它的实现类ImplementationFactory重写这个方法的时候要返回一个Service类型的对象.class ImplementationFactory implements SerivceFactory{
public Service getService(){
return new Implementation();
}这个类继承SerivceFactory接口,为什么返回Implementation()这个类;
}
首先说明的是它返回的不是一个类,而是Implementation这个类的一个实例.
ImplementationFactory 这个类的作用是个工厂它是生产Implementation这个类的对象的.
Service接口可以理解为Implementation的父类,也就是Implementation的实例是Implementation类型的.
也可以是Service类型.