interface Service{
void service() ;
}
interface ServiceFactory{
Service getService() ;
}
class Product1 implements Service{
@Override
public void service() {
System.out.println("产品1服务中.....");
}
}
class ProductFactory1 implements ServiceFactory{
@Override
public Service getService() {
// TODO Auto-generated method stub
return new Product1();
}
}
class Product2 implements Service{
@Override
public void service() {
System.out.println("产品2服务中.....");
}
}
class ProductFactory2 implements ServiceFactory{
public Service getService() {
// TODO Auto-generated method stub
return new Product2();
}
}
public class FactoryTest
{
public static void service(ServiceFactory src){
Service s=src.getService();
s.service() ;
}
public static void main(String []agrs){
FactoryTest.service(new ProductFactory1()) ;
FactoryTest.service(new ProductFactory2() ) ;
}
}