设计模式——工厂方法

设计模式——工厂方法_第1张图片

package factoryMethod;

public class LeiFeng {
	public void sweep()
	{
		System.out.println("sweeping");
	}
	public void wash()
	{
		System.out.println("washing");
	}
}
package factoryMethod;

public class Undergraduate extends LeiFeng{

}
package factoryMethod;

public class Volunteer extends LeiFeng{

}
package factoryMethod;

public interface LeiFengFactory {
	public LeiFeng creaLeiFeng();
}
package factoryMethod;

public class UnderGraduateFactory implements LeiFengFactory{

	@Override
	public LeiFeng creaLeiFeng() {
		return new Undergraduate();
	}
	
}
package factoryMethod;

public class VolunteerFactory implements LeiFengFactory{

	@Override
	public LeiFeng creaLeiFeng() {
		return new Volunteer();
	}

}








你可能感兴趣的:(设计模式——工厂方法)