标签:
1、工厂模式:
package factory;
public interface Boy {
public void drawMan();
}
package factory;
public interface Girl {
public void drawWowen();
}
package factory;
public class HNBoy implements Boy{
@Override
public void drawMan() {
// TODO Auto-generated method stub
System.out.println("HNBoy.drawMan()");
}
}
package factory;
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 HNGirl();
}
}
package factory;
/*
* 新年系列女孩
*/
public class HNGirl implements Girl{
@Override
public void drawWowen() {
// TODO Auto-generated method stub
System.out.println("HNGirl.drawWowen()");
}
}
package factory;
public class MCBoy implements Boy{
@Override
public void drawMan() {
// TODO Auto-generated method stub
System.out.println("MCBoy.drawMan()");
}
}
package factory;
/*
* 圣诞加工厂
*/
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 MCGirl();
}
}
package factory;
/*
* 圣诞女孩类
*/
public class MCGirl implements Girl {
@Override
public void drawWowen() {
// TODO Auto-generated method stub
System.out.println("圣诞系列女孩");
}
}
package factory;
/*
* 人物实现接口
*/
public interface PersonFactory {
//男孩接口
public Boy getBoy();
//女孩接口
public Girl getGirl();
}
标签:
原文地址:http://www.cnblogs.com/yangmei123/p/5374899.html