Continuing the saga of my struggles with ZPatterns, I'm trying to 
work out the best way to implement an object that can be related to 
one of several other objects.

For example, I have a Product class. A Product can come in different 
colors, so I also have a Color class. Products can have two photos of 
the product - small and large. Colors can also have a photo, showing 
the product in that particular color. So, a Photo object can be a 
large product photo, a small product photo, or a color photo.

I can think of two ways to implement this:

1. Add small_photo_id, large_photo_id properties to Product, and 
photo_id property to Color. Then I do something like:


     <dtml-if large_photo_id>
       <dtml-var "Photos.getItem(large_photo_id).viewInstance(...)">
       <form action="selectLargePhoto" method="post">
       <dtml-var "Photos.selectPhotoSnippet(...)">


     photo_id = self.Photos.selectPhoto(REQUEST)

2. Add owner_id, photo_key properties to Photo. Then use:


     <dtml-var "Photos.selectPhotoForOwner(Photos, REQUEST, 
owner_id=id, photo_key='large')">


     <dtml-let photo="defaultRack.getItemForKey(owner_id, photo_key)">
       <dtml-if photo>
         <dtml-var "photo.viewInstance(...)"
         code for selecting/creating photo

The 2nd way seems to go better with OO principles - all handling of 
photos is delegated to the Photos Specialist and the Product doesn't 
care if the photo exists or not, or where it comes from. But it also 
increases complexity in Photos, because I need to implement an 
efficient way to retrieve photos (with a Catalog, or SQL searches), 
and because it introduces the photo_key. Storing photo_id in Product 
eliminates these complexities, but it moves some of the 
responsibility for managing photos into Product.

Can anyone add anything on making the choice? Or maybe a 3rd way I 
haven't thought of?

Itai Tavor                    "Je sautille, donc je suis."
C3Works    [EMAIL PROTECTED]              - Kermit the Frog

"If you haven't got your health, you haven't got anything"

Zope-Dev maillist  -  [EMAIL PROTECTED]
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope )

Reply via email to