trainings/CreatingReliableSoftwareCpp/Presentation/exercises/builder/README.md

1.3 KiB

Linux compilation

> mkdir build
> cd build
> cmake -DCMAKE_BUILD_TYPE=Debug ..
> make

Exercise 1

  • Go to the directory Ship and create class ShipBuilder. The mandatory fields are:
    • name
    • capacity
    • time
  • The non-mandatory fields are:
    • difficultStrategy -> default value should be set as Easy
    • crew -> default value should be set as 10
    • durability -> default value should be set as 1000
    • armor -> default value should be set as 0
    • PrintVisitor -> default value should be set as Pretty Print
  • Try to build your own Ship!

Exercise 2

  • Go to the directory Ship and finish implementation of class ShipJsonBuilder. You should allow building 3 types of ship:
    • Brig
    • Frigate
    • Galoen
  • If you want to read a JSON filed, just use operator[], example: _shipsData["brige"]["armor"]
  • Try to build a ship using a new builder.
  • Try to change some values in ships.json and run binary without recompilation. You should see new values!

Exercise 3

  • Go to the directory Ship and create abstract class FruitFactory.
  • Create FruitFactory
  • Create ItemFactory
  • Create AlcoholFactory
  • Test in main.cpp if you can create any type of cargo
  • How to handle scenario, when different cargo takes other arguments?