For some classes of the C ++ static library, I want to offer different interfaces for the user of the library and the library itself.
Example:
class Algorithm {
public:
void compute(const Data& data, Result& result) const;
void setSecretParam(double aParam);
private:
double m_Param;
}
My first attempt was to create an external interface as ABC:
class Algorithm {
public:
static Algorithm* create();
virtual void compute(const Data& data, Result& result) const = 0;
}
class AlgorithmPrivate : public Algorithm {
public:
void compute(const Data& data, Result& result) const;
void setSecretParam(double aParam);
private:
double m_Param;
}
Pros:
- Algorithm user cannot see the internal interface
Minuses:
- The user must use the factory method to create instances.
- I need to compress the algorithm into the Private algorithm when I want to access secret parameters from inside the library.
I hope you understand what I'm trying to achieve, and I look forward to any suggestions.
source
share