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()这个类;

解决方案 »

  1.   

    ServiceFactory从类名来看就知道这是一个Service的工厂类,用于建造Service对象因为在getService()中有new Implementation(); 对象,所以返回的是Implementation对象
      

  2.   

    interface ServiceFactory{ 
      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类型.
      

  3.   

    还有:有了ImplementationFactory 工厂之后就不用new的方式产生Implementation的实例了可以用工厂调用里面的getService()方法就可以了.