Suppose I have the following classes:
class X;
class Y;
class Collection
{
public:
virtual void AddItemX(X*) = 0;
virtual void AddItemY(Y*) = 0;
//So on...
};
class Collector
{
public:
virtual void Fill(Collection&) = 0;
};
Is there any way to ensure that an implementation of Collector class will fill all the needed items in the passed Collection class?
One method, given a known number of AddItemX() calls is to move those AddItem() functions to protected and have the Collection class keep track of the additions and the number, e.g:
(I actually don’t like this solution, lol, but given your design it would suffice:)
EDIT: For clarification, your Collector could be implemented thusly: