类图
image.pngimage.png
示例代码:
image.pngpackage com.zhs.design.factory.abstract_.factory;
--------------------------------------------------------------------------------
public interface PhoneFactory {
OperationController getOperationController();
InterfaceController getInterfaceController();
}
--------------------------------------------------------------------------------
public class AndroidFactory implements PhoneFactory {
@Override
public OperationController getOperationController() {
return new AndroidOperationController();
}
@Override
public InterfaceController getInterfaceController() {
return new AndroidInterfaceController();
}
}
--------------------------------------------------------------------------------
public class AppleFactory implements PhoneFactory {
@Override
public OperationController getOperationController() {
return new AppleOperationController();
}
@Override
public InterfaceController getInterfaceController() {
return new AppleInterfaceController();
}
}
--------------------------------------------------------------------------------
public class SymbianFactory implements PhoneFactory {
@Override
public OperationController getOperationController() {
return new SymbianOperationController();
}
@Override
public InterfaceController getInterfaceController() {
return new SymbianInterfaceController();
}
}
package com.zhs.design.factory.abstract_.interface_;
--------------------------------------------------------------------------------
public interface InterfaceController {
void show();
}
--------------------------------------------------------------------------------
public class AndroidInterfaceController implements InterfaceController {
public AndroidInterfaceController() {
System.out.println("初始化: AndroidInterfaceController");
}
@Override
public void show() {
System.out.println("Android界面控制");
}
}
--------------------------------------------------------------------------------
public class AppleInterfaceController implements InterfaceController {
public AppleInterfaceController() {
System.out.println("初始化: AppleInterfaceController");
}
@Override
public void show() {
System.out.println("Apple界面控制");
}
}
--------------------------------------------------------------------------------
public class SymbianInterfaceController implements InterfaceController {
public SymbianInterfaceController() {
System.out.println("初始化: SymbianInterfaceController");
}
@Override
public void show() {
System.out.println("Symbian界面控制");
}
}
package com.zhs.design.factory.abstract_.operation;
--------------------------------------------------------------------------------
public interface OperationController {
void work();
}
--------------------------------------------------------------------------------
public class AndroidOperationController implements OperationController {
public AndroidOperationController() {
System.out.println("初始化: AndroidOperationController");
}
@Override
public void work() {
System.out.println("Android操作控制");
}
}
--------------------------------------------------------------------------------
public class AppleOperationController implements OperationController {
public AppleOperationController() {
System.out.println("初始化: AppleOperationController");
}
@Override
public void work() {
System.out.println("Apple操作控制");
}
}
--------------------------------------------------------------------------------
public class SymbianOperationController implements OperationController {
public SymbianOperationController() {
System.out.println("初始化: SymbianOperationController");
}
@Override
public void work() {
System.out.println("Symbian操作控制");
}
}
网友评论