Shopping Cart Object - Simple Question (or is it?)

Shopping Cart Object - Simple Question (or is it?)

Old forum URL: forums.lhotka.net/forums/t/349.aspx


MichaelBosch posted on Monday, June 12, 2006

I've been fighting with one of two ways to implement a shopping cart.  I'm sure both of them will work, but I wanted some quick opinions on which of the two is correct in an object oriented context.

ShoppingCart
+ShoppingCartItems: BusinessListBase
++ShoppingCartItem: BusinessBase

OR

ShoppingCart: BusinessListBase
+ShoppingCartItem: BusinessBase

so... The ShoppingCart object IS A collection of ShoppingCartItems - or - The ShoppingCart HAS A collection of ShoppingCartItems.

I would also want to support things like a property for the created time of the shopping cart, the username of the owner of the shopping cart etc, but I think this should be able to be implemented in either scenario.  Correct?


ajj3085 replied on Monday, June 12, 2006

The fact that you want to have properties on the cart itself suggests you should go with the former route (Cart which has CartItems).

HTH
Andy

malloc1024 replied on Monday, June 12, 2006

Replace the “is-a” test with a “behaves-as-a” test.  Does a shopping cart behave as a collection of shopping cart items?   I would say no.

RockfordLhotka replied on Monday, June 12, 2006

As has been noted, since the cart has properties of its own, then the first option is correct.

Unless of course, you need or want to be stateless (like in an ASP.NET UI), in which case neither is correct and you must have all editable root objects Smile [:)]

skagen00 replied on Tuesday, June 13, 2006

Everything must be editable root objects in ASP.Net?

Isn't that letting the UI dictate the object model? I'm actually having a pretty good go of it with business objects containing collections and so forth.

 

Edit: Sorry, I didn't read your post thoroughly enough where you explicitly said "stateless" interaction on ASP.Net. I guess maintaining an "active object" between postbacks isn't stateless!

 

 

MichaelBosch replied on Tuesday, June 13, 2006

I guess it was an easy question!  Thanks everyone.

Copyright (c) Marimer LLC