I have a class hierarchy where many subclasses derive from base. The base class is designed to be extensible by library users in the future, so the number and names of subclasses are unbounded. One of the services provided by base are input/output port objects that represent conduits by which data gets into and out of the object. Something like this pseudocode:
class input {};
class output {};
class base
{
public:
input &get_input() { return input_; }
output &get_output() { return output_; }
private:
input input_;
output output_;
};
I would like the input and output classes to have two levels of access control:
-
Public functions that are accessible by users of the
baseclass. These would be used to, for instance, inject data into aninputor pull data out of anoutput. -
Protected functions that are accessible only by
baseand its subclasses. These would be used to configure parameters of the input/output ports as appropriate for a specific subclass. I do not want these functions to be accessible to external users ofbaseand its subclasses.
What is an appropriate design pattern to use for this case? My first idea was to make the base class a friend of input and output, but friendship is not inherited by subclasses. I don't think it would be relevant to this question, but you can assume that I can use any facilities up to C++14.
Aucun commentaire:
Enregistrer un commentaire