I'm currently learning about OOP design patterns and I'm working on a project whose main class is roughly organized as follows:
class MainClass {
public:
MainClass(int something, CrazyTypeOfAlgorithm algoType);
double getResult();
private:
std::vector<double> _numbers;
CrazyTypeOfAlgorithm _algoType;
};
where CrazyTypeOfAlgorithm is an enum. Basically, depending on the specific algorithm used, the getResult() function acts accordingly. So far, I've been using simple switch statements in the implementation of the latter. As this class will grow a lot when further algorithms are introduced, I want to encapsulate the algorithm in its own class somehow. I tried out implementing the Strategy Pattern but end up with the problem that the classes implementing different algorithms need to be friend classes of MainClass - as they need to access private member variables of MainClass (e.g. _numbers). How would I accomplish proper and clean encapsulation in this situation?