Hi all!
Suppose I have this two classes:
class ShoppingCart {
addBook(Book book){}
removeBook(Book book) {}
getPrice()
buy()
...
}
and
class Buyer {
private ShoppingCart cart;
spendMoney()
buy();
...
}
When shoppingCart's buy() is called, cart must remove all of it's
books, and the caller gets the price of the books. What is the proper
design here: should buyer know in which order class ShoppingCart works
(cart.getPrice, cart.buy() in which cart remove all the books), or
should buyer call cart.buy, cart.getPrice (order again), and then
buyer would remove all the books through for loop, or should I use
somethin like this
cart.buy(Buyer buyer), and inside cart.buy cart calls
buyer.spendMoney()?
Thanks in advance
TobiMc3@gmail.com - 14 May 2007 18:06 GMT
On May 14, 11:49 am, ida...@gmail.com wrote:
> Hi all!
>
[quoted text clipped - 28 lines]
>
> Thanks in advance
I'd say, that it really depends on what your are designing overall. I
mean, the ideal situation is that the classes know as little about the
internals of the other as possible, and that they are loosely coupled.
Tobi
visionset - 14 May 2007 18:52 GMT
> Hi all!
>
[quoted text clipped - 22 lines]
> should buyer call cart.buy, cart.getPrice (order again), and then
> buyer would remove all the books through for loop,
Yes this one
Then remove the buy() method from the cart, it doesn't buy, it removes items
you said.
But really as mentioned a fuller requirements spec is required to make these
kind of design decisions.
> or should I use
> somethin like this
> cart.buy(Buyer buyer), and inside cart.buy cart calls
> buyer.spendMoney()?

Signature
Mike W