Patterns

The rsc::patterns namespace currently includes the following pattern implementations:

Singleton

The Singleton class can be used to ensure that at most one object of a given class exists at any time. It also encapsulates the creation and destruction of that object. Example:

template<typename Key, typename Interface>
class SingletonFactory: public Singleton<SingletonFactory<Key, Interface> > ,
                        public Factory<Key, Interface> {
  friend class Singleton<SingletonFactory<Key, Interface> > ;
private:
  SingletonFactory();
};

and
SingletonFactory& factory = SingletonFactory::getInstance();

Factory

The *Factory family of classes implements different variations of the factory pattern. In all cases, keys of some type are used to identify implementations of a common interface that is specified as a template argument of the factory class. Example:

typedef rsc::patterns::SingletonFactory<std::string, my_interface> my_factory;

ContainerProxy

The ContainerProxy classes can be considered variants of the proxy pattern. The can be used to expose a modified interface to a container. For example, elements can be transformed on-the-fly when they are accessed.