Builder.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #include "Builder.h"
  2. #include "spdlog.h"
  3. void buildSunnyShip()
  4. {
  5. ShipFactory* factory = new ShipFactory();
  6. SunnyShipBuilder* builder = new SunnyShipBuilder();
  7. factory->setBuilder(builder);
  8. /* 创建简约型 */
  9. factory->builderSimpleShip();
  10. SunnyShip* ship = builder->getShip();
  11. SPDLOG_INFO("Sunny简约型:");
  12. ship->ShowParts();
  13. delete ship;
  14. /* 创建标准型 */
  15. builder->reset();
  16. factory->builderStandardShip();
  17. ship = builder->getShip();
  18. SPDLOG_INFO("Sunny标准型:");
  19. ship->ShowParts();
  20. delete ship;
  21. /* 创建豪华型 */
  22. builder->reset();
  23. factory->builderRegalShip();
  24. ship = builder->getShip();
  25. SPDLOG_INFO("Sunny豪华型:");
  26. ship->ShowParts();
  27. delete ship;
  28. }
  29. /* 创建Merry号 */
  30. void buildMerryShip()
  31. {
  32. ShipFactory* factory = new ShipFactory();
  33. MerryShipBuilder* builder = new MerryShipBuilder();
  34. factory->setBuilder(builder);
  35. /* 创建简约型 */
  36. factory->builderSimpleShip();
  37. MerryShip* ship = builder->getShip();
  38. SPDLOG_INFO("Merry简约型:");
  39. ship->ShowParts();
  40. delete ship;
  41. /* 创建标准型 */
  42. builder->reset();
  43. factory->builderStandardShip();
  44. ship = builder->getShip();
  45. SPDLOG_INFO("Merry标准型:");
  46. ship->ShowParts();
  47. delete ship;
  48. /* 创建豪华型 */
  49. builder->reset();
  50. factory->builderRegalShip();
  51. ship = builder->getShip();
  52. SPDLOG_INFO("Merry豪华型:");
  53. ship->ShowParts();
  54. delete ship;
  55. }