BookShelf *bookShelf = catalog.item("Fantasy");
BookShop::Adapter aShop(bookShop());BookShelf::Adapter aBookShelf = aShop.item<BookShop::Shelf::Book>()->adapter();NewspaperShelf *pNewspaperShelf = aShop.item<BookShop::Shelf::Newspaper>();auto aMagazineShelf = aShop.item<BookShop::Shelf::Magazine>()->adapter();
// Itemclass Item{public: Container* container() { return container_; } const Container* container() const { return const_cast<Item*>(this)->container(); }private: Container* container_; ...};// TheItem/// Thing class template to generate more closured container related interfacetemplate <typename ContainerT, typename BaseT = Item>class TheItem : public BaseT{ typedef BaseT Base;public: ContainerT* container() { return static_cast<ContainerT*>(Base::container()); } const ContainerT* container() const { return static_cast<const ContainerT*>(Base::container()); } ...};
// ConcreateItemclass ConcreateItem : public TheItem<ConcreateContainer, Item>{ ...};...ConcreateItem item;item.container(); // returns ConcreateContainer*
class ConcreateItem : public TheItem<ConcreateContainer, Item>