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;
};
然后,建立符合接口的储存。 现在,我的问题是:
- 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?