[Zope-dev] ZPatterns, ZClasses, Specialists: Assigning responsibilities

Itai Tavor itai@optusnet.com.au
Mon, 18 Dec 2000 16:21:29 +1100


>Itai Tavor wrote:
>
>>I have the following ZClasses, with matching Specialists: Product, 
>>Graphic, Order, OrderLineItem. When a customer adds a product to 
>>their order, they have to provide a graphic file which will be 
>>printed on the product (imagine buying a lunch box with your cat's 
>>photo on it). The Graphics Specialist can provide a 
>>addGraphicSnippet form. But who's responsible for asking for this 
>>graphic when adding the product to the order? Is it still the 
>>Product object? But a Product turns into a Product-with-Graphic 
>>only when it's a part of an order, so is it correct for the Product 
>>to even know about Graphics? the alternative is to move the 
>>addToOrder methods to either Order or OrderLineItems, but this 
>>doesn't make any more sense because these would then have to know a 
>>lot more about a Product than is good for them. Any ideas?
>
>Sounds to me like you have a new type of Product.
>
>You have your basic products (of which there are many kinds), and 
>you have ProductWithGraphic products. A ProductWithGraphic is a 
>"calculated product": it is composed of a basic product and a 
>graphic. Its cost, delivery time, packing charge, and so forth, are 
>calculated based on the combination of the basic product and the 
>graphic.
>
>To the rest of the application, a ProductWithGraphic is just another 
>kind of product.

Thanks, this is an interesting suggestion... but I'm not sure how it 
would work. It gets very complicated when I try to think of 
implementing it.

The application accesses products using a Products Specialist, with a 
Rack for each type of product. The contents of these Racks make up 
the Product catalog of the store. The Products Specialist implements 
the role of 'things that can be added to an order'.

On the other hand, ProductWithGraphic is not part of the store's 
catalog. A new instance of it is created every time a shopper adds a 
product to their cart. So it does not fill the role 'thing that can 
be added to an order'. rather, its role is of something that has been 
ordered and is being fabricated.

So treating ProductWithGraphic as another kind of Product doesn't 
seem to make sense... I do realize I need a new kind of product - 
CustomizableProduct. But, looking at the role of a 
ProductWithGraphic, it looks a lot more like an OrderLineItem than a 
Product. It's part of an order. It's state changes are part of the 
order handling process. So wouldn't it make sense to have a 
lineItemWithGraphic object in the OrderLineItems Specialist? That 
seems much simpler to me... except that the responsibilities question 
in it is still open. Back to square 1.

This is how I see it:

- Products Specialist
     productRack
     customizableProductRack

- OrderLineItem Specialist
     lineItemRack
     lineItemWithGraphicRack

- product.addMeToOrder():
     order.addLineItem(product_id=id, add='lineItem')

- custimazable_product.addMeToOrder():
     order.addLineItem(product_id=id, add='lineItemWithGraphic')

I imagine, then, that the UI for uploading the graphic would be 
included in product.addMeToOrderForm, using a UI snippet from the 
OrderLineItemsWithGraphic Specialist. Then I could pass REQUEST on to 
order.addLineItem and to OrderLineItemsWithGraphic.add, which would 
then upload the file?

Woof... so long. I'd appreciate any comments on this - especially on 
the question on whether it's better to have a specialized type of 
OrderLineItem, or to link the standard OrderLineItem to a Product 
object in case of a standard product, or, in the case of a 
customizable product, to a new object which stores the graphic and 
tracks the fabrication of the customized item.

TIA

Itai
-- 
Itai Tavor                    "Je sautille, donc je suis."
C3Works    itai@c3works.com              - Kermit the Frog

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