public CastlevaniaGame(String begin, String stop, String play) {
this.begin = begin;
this.stop = stop;
this.play = play;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getBegin() {
return begin;
}
public void setBegin(String begin) {
this.begin = begin;
}
public String getStop() {
return stop;
}
public void setStop(String stop) {
this.stop = stop;
}
public String getPlay() {
return play;
}
public void setPlay(String play) {
this.play = play;
}
}
4、定义开发游戏工厂接口 GameFactory .java
/**
-
开发游戏工厂类
-
@author DarkKing
*/
public interface GameFactory {
public Game createGame(String gameName);
}
5、定义开发游戏工厂实现类 GameFactoryImpl .java
/**
-
开发游戏工厂类
-
@author DarkKing
*/
@Component
public class GameFactoryImpl implements GameFactory{
@Override
public Game createGame(String gameName) {
Game game= null;
if(gameName.equals(“superMario”)){
game = new CangSmallMovie(“超级玛丽”);
}else if(gameName.equals(“Castlevania”)){
game= new JiaSmallMovie(“恶魔城”);
}
//开发游戏过程
//…………
//此处省略一万字
return game;
}
}
三、工厂模式
=======
1、工厂模式介绍
工厂模式属于创建型模式,它提供了一种创建对象的最佳方式。定义一个创建对象的接口, 让其子类自己决定实例化哪一个工厂类,工厂模式使其创建过程延迟到子类进行。类图如下:
-
产品接口(Product):产品接口用于定义产品类的功能,具体工厂类产生的所有产品都 必须实现这个接口。调用者与产品接口直接交互,这是调用者最关心的接口;
-
具体