I have a class called PatchCollection. It is in charge of creating a bunch of Patch objects. It stores them in a member variable of type std::set. Now I want to loop over all of the patches from outside the class. That is:
MyClass
{
PatchCollection Patches;
void DoSomething()
{
// Loop over all patches in Patches
}
};
What is the "best" way to go about this? I've though of:
1) Of course I could make a std::set<Patch>& GetPatches() function, but then I need to know that the patches are stored in a std::set, which seems to violate some principles of OO (i.e. the calling function should not care about the internal details).
2) I could make a typedef of std::set<Patch> ContainerType. Then I could just use PatchCollection::ContainerType::iterator in the calling function. This is better than (1), but it still indicates an STL container is being used.
3) I could "reimplement" the std::set function - making a PatchCollection::GetIterator(), PatchCollection::NextItem(), etc - but this seems like a lot of duplication.
Any thoughts? What would you do :) ?
David