标签:img 相关 使用 ali voc system rpe ignore ace
public interface Computer { } public class DellComputer implements Computer { public DellComputer(){ System.out.println("戴尔"); } } public class Lenovo implements Computer { public Lenovo(){ System.out.println("联想"); } } public class SimpleComputerFactory { static Computer createComputer(String type){ Computer computer =null; if("dell".equalsIgnoreCase(type)){ computer = new DellComputer(); }else if("lenovo".equalsIgnoreCase(type)){ computer = new Lenovo(); } return computer; } }
public class SimpleFactoryTestDemo { public static void main(String[] args){ SimpleComputerFactory.createComputer("dell"); SimpleComputerFactory.createComputer("lenovo"); } }
public interface Computer { } public class Lenovo implements Computer { public Lenovo(){ System.out.println("联想"); } } public class ThinkPad implements Computer { public ThinkPad(){ System.out.println("ThinkPad"); } } public interface ComputerFactory { Computer createCompute(String type) ; } public class LenovoComputerFactory implements ComputerFactory{ @Override public Computer createCompute(String type) { Computer computer = null; if("lenovo".equalsIgnoreCase(type)){ computer = new Lenovo(); }else if("thinkpad".equalsIgnoreCase(type)){ computer = new ThinkPad(); } return computer; } }
public class ComputerFactoryTestDemo { public static void main(String[] args){ ComputerFactory lenovoComputerFactory = new LenovoComputerFactory(); lenovoComputerFactory.createCompute("lenovo"); lenovoComputerFactory.createCompute("thinkpad"); } }
//键盘接口 public interface KeyBoard { } public class LogitechKeyBoardA implements KeyBoard { public LogitechKeyBoardA(){ System.out.println("罗技键盘A"); } } public class LogitechKeyBoardB implements KeyBoard { public LogitechKeyBoardB(){ System.out.println("罗技键盘B"); } } public class RazerKeyBoardA implements KeyBoard { public RazerKeyBoardA(){ System.out.println("雷蛇键盘A"); } } public class RazerKeyBoardB implements KeyBoard { public RazerKeyBoardB(){ System.out.println("雷蛇键盘B"); } } //鼠标接口 public interface Mouse { } public class LogitechMouseA implements Mouse{ public LogitechMouseA(){ System.out.println("罗技鼠标A"); } } public class LogitechMouseB implements Mouse{ public LogitechMouseB(){ System.out.println("罗技鼠标B"); } } public class RazerMouseA implements Mouse{ public RazerMouseA(){ System.out.println("雷蛇鼠标A"); } } public class RazerMouseB implements Mouse{ public RazerMouseB(){ System.out.println("雷蛇鼠标B"); } } //外设工厂接口,负责生产键盘和鼠标 public interface PeripheralsFactory { Mouse createMouse(String type); KeyBoard createKeyBord(String type); } public class LogitechPeripheralsFactory implements PeripheralsFactory { @Override public Mouse createMouse(String type) { Mouse mouse = null; if ("A".equalsIgnoreCase(type)) { mouse = new LogitechMouseA(); } else if ("B".equalsIgnoreCase(type)) { mouse = new LogitechMouseB(); } return mouse; } @Override public KeyBoard createKeyBord(String type) { KeyBoard keyBoard = null; if ("A".equalsIgnoreCase(type)) { keyBoard = new LogitechKeyBoardA(); } else if ("B".equalsIgnoreCase(type)) { keyBoard = new LogitechKeyBoardB(); } return keyBoard; } } public class RazerPeripheralsFactory implements PeripheralsFactory { @Override public Mouse createMouse(String type) { Mouse mouse = null; if ("A".equalsIgnoreCase(type)) { mouse = new RazerMouseA(); } else if ("B".equalsIgnoreCase(type)) { mouse = new RazerMouseB(); } return mouse; } @Override public KeyBoard createKeyBord(String type) { KeyBoard keyBoard = null; if ("A".equalsIgnoreCase(type)) { keyBoard = new RazerKeyBoardA(); } else if ("B".equalsIgnoreCase(type)) { keyBoard = new RazerKeyBoardB(); } return keyBoard; } }
public class PeripheralsAbstractFactoryTestDemo { public static void main(String[] args){ PeripheralsFactory razerFactory = new RazerPeripheralsFactory(); razerFactory.createKeyBord("A"); razerFactory.createKeyBord("B"); razerFactory.createMouse("A"); razerFactory.createMouse("B"); PeripheralsFactory logitechFactory = new LogitechPeripheralsFactory(); logitechFactory.createKeyBord("A"); logitechFactory.createKeyBord("B"); logitechFactory.createMouse("A"); logitechFactory.createMouse("B"); } }
标签:img 相关 使用 ali voc system rpe ignore ace
原文地址:https://www.cnblogs.com/camcay/p/12355096.html