Scenario builder 3 : remove dependency to the study #1593
Replies: 1 comment 2 replies
-
How to remove the dependency to StudyThis suggestion about scenario builder internal design implies to separate the fetch of information in the study from the scenario builder usual actions (resetting, reading input from file, saving its content to file, apply to matrices, ...). We call these classes scenario category properties (for lack of a better name). Each scenario category has its own property class. This suggestion of internal design implies that we instantiate these property classes in the class Rules's constructor, and that's the (only) place where we notice the dependency of the scenario builder to the study. But we can improve this, and possibly remove all dependency to the study, by instantiating the scenario category property classes outside the scenario builder, and add these object to the scenario builder : Rules::Rules(Study& study, std::string name) : name_(name)
{
...
}
Rules::addCategory(std::string categoryName, std::unique_ptr<MatrixProperties> matrixProperty)
{
categories_[categoryName] = matrixProperty;
} And then, on the client side : int main()
{
....
Rules rules("Custom rule set");
// Wind properties
auto windMatrixProperties = std::make_unique<WindMatrixProperties>(study);
windMatrixProperties->build();
rules.add("Wind", std::make_unique<SingleScenarioCategory>(windMatrixProperties));
// Thermal properties
auto thermalScenario = std::make_unique<MultipleScenarioCategory>( /* no arg needed */ );
for(auto& area : study.areas)
{
auto thermalMatrixProperties = std::make_unique<ThermalMatrixProperties>(area);
thermalMatrixProperties->build();
thermalScenario->add(area->name,
std::make_unique<SingleScenarioCategory>(area->name, thermalMatrixProperties));
}
rules.add("Thermal", thermalScenario);
...
} Doing this way, we move the dependency to the study from the scenario builder to categories properties (classes MatrixProperties). |
Beta Was this translation helpful? Give feedback.
-
This page discusses a particular aspect of this more general discussion
Scenario builder is dependent to the Study : not only the scenario builder is nested in the Study (have a look at the general discussion), but it's also dependent on the Study. At least it prevents the scenario builder from being tested in isolation.
Few examples of reasons for which scenario builder needs the study :
Beta Was this translation helpful? Give feedback.
All reactions