I want to have a Storage interface(abstract class) and a set of Storage implementations (SQLite, MySQL, Memcached..) for storing objects of a known class and retrieving subsets from the Storage.
To me the clear interface would be:
class Storable{int id; blah; blah; blah; string type;};
class Storage{
virtual Storage::iterator get_subset_of_type(string type) = 0;
virtual Storage::iterator end)_ = 0;
virtual void add_storable(Storable storable) = 0;
};
And then create implementations of Storage that fulfill the interface. Now, my problem is the following:
- Iterators can't be polymorphic as they are returned by value.
- I can't just subclass Storage::iterator for my given Storage implementation
- I thought about having a wrapper iterator that wraps and does pimpl over a polymorphic type that the Storage implementations subclass, but then I need to use dynamic memory and allocate all over the place.
Any hint?