/**
* @author haowq 2021/4/25 10:06
* 簡(jiǎn)單工廠挡逼,擴(kuò)展性不好,擴(kuò)展違反開閉原則
*/
public class SimpleFactory {
public Car createCar(){
return new Car();
}
public Plane createPlane(){
return new Plane();
}
//other create operator
}
/**
* @author haowq 2021/4/27 10:01
* 抽象工廠,有產(chǎn)品族的概念装蓬,兩個(gè)維度著拭,工廠維度和產(chǎn)品維度,
* 工程維度上方便擴(kuò)展牍帚,產(chǎn)品維度擴(kuò)展的話違反開閉原則
*/
public interface AbstractFactroy {
Tank newTank();
Bullet newBullet();
}
/**
* Good 工廠
*/
public class GoodAbastractFactory implements AbstractFactroy {
@Override
public Tank newTank() {
return new GoodTank();
}
@Override
public Bullet newBullet() {
return new GoodBullet();
}
}
/**
* Bad 工廠
*/
public class BadAbastractFactory implements AbstractFactroy {
@Override
public Tank newTank() {
return new BadTank();
}
@Override
public Bullet newBullet() {
return new BadBullet();
}
}