public abstract class AbstractFactory {
abstract GameController creatOperation();
abstract GameController creatInterface();
}
class WindowPhoneFactory extends AbstractFactory{
@Override
GameController creatOperation() {
System.out.println("创建window手机的游戏操作控制类");
return new OperationWController();
}
@Override
GameController creatInterface() {
System.out.println("创建window手机的游戏界面控制类");
return new InterfaceWController();
}
}
class SymbianFactory extends AbstractFactory{
@Override
GameController creatOperation() {
System.out.println("创建Symbian手机的游戏操作控制类");
return new OperationSController();
}
@Override
GameController creatInterface() {
System.out.println("创建Symbian手机的游戏界面控制类");
return new InterfaceSController();
}
}
class AndroidFactory extends AbstractFactory{
@Override
GameController creatOperation() {
System.out.println("创建Android手机的游戏操作控制类");
return new OperationAController();
}
@Override
GameController creatInterface() {
System.out.println("创建Android手机的游戏界面控制类");
return new InterfaceAController();
}
}
public abstract class GameController {
abstract void control();
}
class OperationWController extends GameController{
@Override
void control() {
System.out.println("进行window游戏操作控制");
}
}
class InterfaceWController extends GameController{
@Override
void control() {
System.out.println("进行widnow游戏界面控制");
}
}
class OperationSController extends GameController{
@Override
void control() {
System.out.println("进行Symbain游戏操作控制");
}
}
class InterfaceSController extends GameController{
@Override
void control() {
System.out.println("进行Symbain游戏界面控制");
}
}
class OperationAController extends GameController{
@Override
void control() {
System.out.println("进行Android游戏操作控制");
}
}
class InterfaceAController extends GameController{
@Override
void control() {
System.out.println("进行Android游戏界面控制");
}
}
public static void main(String[] arg){
WindowPhoneFactory factory=new WindowPhoneFactory();
GameController interfaceWController = factory.creatInterface();
GameController operationWController = factory.creatOperation();
interfaceWController.control();
operationWController.control();
SymbianFactory sfactory=new SymbianFactory();
GameController sinterfaceWController = factory.creatInterface();
GameController soperationWController = factory.creatOperation();
sinterfaceWController.control();
soperationWController.control();
AndroidFactory afactory=new AndroidFactory();
GameController ainterfaceWController = factory.creatInterface();
GameController aoperationWController = factory.creatOperation();
ainterfaceWController.control();
aoperationWController.control();
}