On May 14, 11:49 am, ida...@gmail.com wrote:
> 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
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
|