抽象工厂模式
Boy.java
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
package ff; public interface Boy { public void drawboy(); }
Girl.java
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
package ff; public interface Girl { public void drawgril(); }
HNBoy.java
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
package ff; public class HNBoy implements Boy { @Override public void drawboy() { // TODO Auto-generated method stub System.out.println("--新年系列的男孩子啊---"); } }
HNGril.java
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
package ff; public class HNGril implements Girl { @Override public void drawgril() { System.out.println("--新年系列的女孩子啊---"); } }
MCBoy.java
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
package ff; public class MCBoy implements Boy { @Override public void drawboy() { // TODO Auto-generated method stub System.out.println("--圣诞系列的男孩子啊---"); } }
MCGril.java
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
package ff; /* * 圣诞系列的女孩子啊 */ public class MCGril implements Girl { @Override public void drawgril() { System.out.println("--圣诞系列的女孩子啊---"); } }
PersonFactory.java
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
package ff; /* * 人物的实现接口; * * */ public interface PersonFactory { //男孩接口 public Boy getboy(); //女孩接口; public Girl getgirl(); }
HNFactory.java
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
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
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
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
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
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(); } }