[Zope-dev] ZPatterns: DropZone example

Steve Alexander steve@cat-box.net
Wed, 06 Sep 2000 13:31:45 +0100


Steve Spicklemire wrote:
> 
> Hi Steve, (and any others who might care to comment....)
> 
>    I've been sorting through old ZPatterns email looking for
> inspiration and I came upon this:
> 
> >>>>> "Steve" == Steve Alexander <steve@cat-box.net> writes:
> 
>     Steve> Hi folks,
> 
>     Steve> I've been looking at the DropZone example Phillip Eby
>     Steve> provided on the ZPatterns Wiki.
> 
>     Steve> http://www.zope.org/Members/pje/Wikis/ZPatterns/DropZoneExample
> 
>     Steve> I've decided to start implementing it, so as to give myself
>     Steve> an educational experience in using ZPatterns.
> 
> Did you get very far with this?  

I designed it in some detail on paper. I didn't get into implementation
though; a real project using ZPatterns got there first :-)

<deletia>
> but this smells a little bit like the 'controller' paradigm that Coad et. al.
> are so opposed to... It seems like 'big brother' for the ShopperManager to
> be meddling with the individual items in a shopper's basket... but maybe
> that's the best way...

If the ShopperManager specialist is responsible for the basket
propertysheet, then it should provide methods to add and remove items
from the basket propertysheet.

In plain language, the Shoppers Specialist is responsible for a
Shopper's basket.

Let's say you're integrating the DropZone system with Etailer, so that
SkyDivers can buy parachutes at our on-line shop.

Somewhere, you'll have to ensure that SkyDivers get a Basket
propertysheet. Perhaps they get this on entering the shop.
When you're in a real physical shop, the basket belongs to the shop. I
think it is quite natural that the Shoppers specialist is responsible
for taking things from the shop's shelves and putting them in the shop's
basket that the shopper is holding.

You can alter your SkyDiver class so that it has methods for adding
items to the basket and so forth, that forward on to the Shoppers
specialist. However, this seems unnatural to me. Can a SkyDiver always
add an item to her basket, or can she only do this when she is in the
shop?

> ShopperManager.InsertItemIntoShoppersBasket(shopper=aShopper, mi=aMarketItem,
> quantity=qty),

Seeing as the context is clearly ShopperManger (or Shoppers), I don't
think there's any need for such a long method name. The context clearly
involves shoppers and baskets, so perhaps AddToBasket(shopper, item,
qty) would be clear enough?

If anything, AddToBasket could be a method of MarketItem.
Item.addToBasketOf(Shopper).
However, if Items live on Shelves in Isles in a Shop, addToBasketOf
could be a method of the Shop, that gets found by acquisition from items
in the shop. And, perhaps we know who the Shopper is from the
AUTHENTICATED_USER of the REQUEST.

The Zope object heirarchy might look like this:

Shop
 |-addToBasket(qty)  (forwards to
ShoppersSpecialist.addToBasket(shopper, item, qty))
 |
 |-ParachutesIsle
     |-LargeSizeShelf
          |-BlueParachute



Again, I don't know much about Etailer, so I'm kind of guessing.

Hope this is helpful.

--
Steve Alexander
Software Engineer
Cat-Box limited
http://www.cat-box.net