一、C++常用设计模式 :工厂模式
- 1、why
- 2、when
- 3、what
- 4、how
1、why
#include <iostream>class Phone {
};class XiaoMi : public Phone {
};class Apple : public Phone {
};class Huawei : public Phone {
};class Oppo : public Phone {
};class Vivo : public Phone {
};int main() {XiaoMi* xiaomiPhone = new XiaoMi();Apple* applePhone = new Apple();Huawei* HuaweiPhone = new Huawei();Oppo* oppo = new Oppo();Vivo* vivo = new Vivo();return 0;
}