Skip to content

Replace simulation manager interface with a builder #19

@anderspkd

Description

@anderspkd

The sim::Manager interface is a bit bothersome to handle from a user's point of view.
A much better design would be to construct a Manager using a builder. This has a number of benefits:

  • No need to pass around an std::unique_ptr for the manager.
  • Easier to customize the simulation. E.g., no need to subclass some particular subclass of sim::Manager and then pass an std::ostream object to the constructor in order to output results to a file. Something like builder.setOutput(some_stream) should do the trick.
  • Allows making the object that the builder builds (the manager) be responsible for also running the simulation.

Builder proposal:

class SimulationBuilder {
public:
  static SimulationBuilder create();
  SimulationBuilder& outputTo(const std::string& filename);
  SimulationBuilder& outputToStdout();
  template <typename FUNC>
  SimulationBuilder& protocolCreator(FUNC&& creator);
  SimulationBuilder& networkConfig(...);
  
  Simulator build();
};

auto builder = SimulationBuilder::create();
// bla bla

auto simulator = builder.build();

// runs the simulation
simulator.run();

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions