In my audio C++ project, I have an abstract class called ScoreReader. ScoreReader has as…
Jump to turn (6)
- 1In my audio C++ project, I have an abstract class called ScoreReader. ScoreReade
- 2This proposal sounds interesting, however: In a simple case, I still need to imp
- 3Ok, done. I also moved AddParameters to the private part of the class, since the
- 4Please provide feedback also on this part of code. IAudioProcessor also has a vi
- 5I think I was not enough clear on question 2. Is beneficial that the methods ins
- 6I like clarity, indeed even myself from time to time when I come back to some pa
- User
In my audio C++ project, I have an abstract class called ScoreReader. ScoreReader has as public method: void ConfigureParameters() { InitializeParameters(); // other stuff } with a protected method: virtual void InitializeParameters() = 0; Moreover it also contains this function: void AddParameters(const std::initializer_liststd::string ¶ms) . Then, I have concrete class of AudioProcessor that inherits from ScoreReader. Inside AudioProcessor, the actual call is to call ConfigureParameters() and then to implement: void InitializeParameters() final { AddParameters({"amplitude", "frequency"}); } with amplitude and frequency two strings that represents generic parameters for that concrete instance. In my original idea, I forced to have the virtual method InitializeParameters indeed to force the user to implement it and call AddParameters. However, while reviewing the code I have the following proposal, that inside ScoreReader I have: void ConfigureParameters(const std::initializer_list& params) { AddParameters(params); // other stuff } Pros: this change will enhance clarity and avoid an extra layer of complexity. Cons: Without forcing the user to implement a virtual function, I have less assurance that the user will implement such function. I say less because the user can implement a "do nothing" function for InitializeParameters and that is. On the contrary, I think it is not reasonable to perform some checks on params, like to be not empty, because it is a strange behavior but I can not be sure that an user won't write an AudioProcessor without parameters. Please provide me feedback on this topic.