抽象工厂模式
不能添加单个产品,产品族
public interface Seat {
void anmo();
}
class GoodSeat implements Seat {
@Override
public void anmo() {
System.out.println("可以按摩");
}
}
class LowSeat implements Seat {
@Override
public void anmo() {
System.out.println("不可以按摩");
}
}
public interface Tyre {
void piaoyi();
}
class GoodTyre implements Tyre{
@Override
public void piaoyi() {
System.out.println("可以漂移");
}
}
class LowTyre implements Tyre{
@Override
public void piaoyi() {
System.out.println("不可以漂移");
}
}
public interface Engine {
void run();
void start();
}
class GoodEngine implements Engine {
@Override
public void run() {
System.out.println("跑的快");
}
@Override
public void start() {
System.out.println("启动的快");
}
}
class LowEngine implements Engine {
@Override
public void run() {
System.out.println("跑的慢");
}
@Override
public void start() {
System.out.println("启动的慢");
}
}
public interface CarFactory {
Engine creatEngine();
Seat creatSeat();
Tyre creatTyre();
}
public class GoodCarFactory implements CarFactory{
@Override
public Engine creatEngine() {
return new GoodEngine();
}
@Override
public Seat creatSeat() {
return new GoodSeat();
}
@Override
public Tyre creatTyre() {
return new GoodTyre();
}
}
public class LowCarFactory implements CarFactory{
@Override
public Engine creatEngine() {
return new LowEngine();
}
@Override
public Seat creatSeat() {
return new LowSeat();
}
@Override
public Tyre creatTyre() {
return new LowTyre();
}
}