package org.ustc.factory;
public class LeiFeng {
public void buyRice(){
System.out.println("卖大米");
}
public void wash(){
System.out.println("洗衣");
}
public void Sweep(){
System.out.println("扫地");
}
}
package org.ustc.factory;
public class Volunteer extends LeiFeng {
}
package org.ustc.factory;
public class Undergraduate extends LeiFeng {
}
package org.ustc.factory;
public interface Factory {
public LeiFeng createInstance();
}
package org.ustc.factory;
public class CraeteVolunteer implements Factory {
@Override
public LeiFeng createInstance() {
// TODO Auto-generated method stub
return new Volunteer();
}
}
package org.ustc.factory;
public class CreateUnderGradutate implements Factory {
@Override
public LeiFeng createInstance() {
// TODO Auto-generated method stub
return new Undergraduate();
}
}
package org.ustc.factory;
public class Main {
public static void main(String[] args) {
Factory fact = new CreateUnderGradutate();
LeiFeng student = fact.createInstance();
student.buyRice();
}
}