package com.mhm.abstractfactory;
import com.mhm.simplefactory.Car;
public interface BenzCar extends Car {
}
package com.mhm.abstractfactory;
public class BenzBussinessCar implements BenzCar {
@Override
public void drive() {
System.out.println("开奔驰商务车");
}
}
package com.mhm.abstractfactory;
public class BenzSportCar implements BenzCar {
@Override
public void drive() {
System.out.println("开奔驰运动车");
}
}
package com.mhm.abstractfactory;
import com.mhm.simplefactory.Car;
public interface BmwCar extends Car {
}
package com.mhm.abstractfactory;
public class BmwBussinessCar implements BenzCar {
@Override
public void drive() {
System.out.println("开宝马商务车");
}
}
package com.mhm.abstractfactory;
public class BmwSportCar implements BenzCar {
@Override
public void drive() {
System.out.println("开宝马运动车");
}
}
package com.mhm.abstractfactory;
import com.mhm.simplefactory.Car;
public interface IDriver {
public Car driverSoprtBenz();
public Car driverBusinessBenz();
public Car driverSportBmw();
public Car driverBusinessBmw();
}
package com.mhm.abstractfactory;
import com.mhm.simplefactory.Car;
public class Driver implements IDriver {
@Override
public Car driverBusinessBenz() {
return new BenzBussinessCar();
}
@Override
public Car driverBusinessBmw() {
return new BmwBussinessCar();
}
@Override
public Car driverSoprtBenz() {
return new BenzSportCar();
}
@Override
public Car driverSportBmw() {
return new BmwSportCar();
}
}
package com.mhm.abstractfactory;
import com.mhm.simplefactory.Car;
public class Magnate {
public static void main(String[] args) {
IDriver idriver = new Driver();
Car car = idriver.driverBusinessBmw();
car.drive();
}
}