Boy.java
package ff; public interface Boy { public void drawboy(); }
Girl.java
package ff; public interface Girl { public void drawgril(); }
HNBoy.java
package ff; public class HNBoy implements Boy { @Override public void drawboy() { // TODO Auto-generated method stub System.out.println("--新年系列的男孩子啊---"); } }
HNGril.java
package ff; public class HNGril implements Girl { @Override public void drawgril() { System.out.println("--新年系列的女孩子啊---"); } }
MCBoy.java
package ff; public class MCBoy implements Boy { @Override public void drawboy() { // TODO Auto-generated method stub System.out.println("--圣诞系列的男孩子啊---"); } }
MCGril.java
package ff; /* * 圣诞系列的女孩子啊 */ public class MCGril implements Girl { @Override public void drawgril() { System.out.println("--圣诞系列的女孩子啊---"); } }
PersonFactory.java
package ff; /* * 人物的实现接口; * * */ public interface PersonFactory { //男孩接口 public Boy getboy(); //女孩接口; public Girl getgirl(); }
HNFactory.java
package ff; public class HNFactory implements PersonFactory { @Override public Boy getboy() { // TODO Auto-generated method stub return new HNBoy(); } @Override public Girl getgirl() { // TODO Auto-generated method stub return new HNGril(); } }
MCFactory.java
package ff; /* * * 圣诞系列男孩加工厂; */ public class MCFactory implements PersonFactory { @Override public Boy getboy() { // TODO Auto-generated method stub return new MCBoy(); } @Override public Girl getgirl() { // TODO Auto-generated method stub return new MCGril(); } }
test.java
package ff; public class test { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub PersonFactory factory = new MCFactory(); Girl gril = factory.getgirl(); gril.drawgril(); } }