title: Design pattern for reducing code duplication in different types of collections of the same object
body: <p>Let's assume I have a class which defines an image object. The image can belong to an album, and the album can belong to a folder. This data is stored in MySQL. The data is also cached. In the cache, it is stored in a denormalized form i.e. folders keep track of images they are associated with, and so do albums. This is implemented for performance reasons. </p>
  
  <p>Whenever a photo is created now, it is added to both the folder and the album in the cache. Because the code is the same for adding the photos to the cache, and only the cache keys change, a separate object is made called CachedImageSet. The folder and the album instantiate CachedImageSet with their unique id and the type of collection, and they call CachedImageSet to add and remove images and to get a list of images in the set.</p>
  
  <p>I don't want client code to directly interact with CachedImageSet, so I have methods in the folder and album classes that are wrappers for the methods of CachedImageSet. This results in a lot of code duplication. Is there any design pattern that would help me get rid of this duplication? I'm using PHP, MySQL, and Redis (for the cache-layer). </p>