Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > [Newbie] design question

Reply
Thread Tools

[Newbie] design question

 
 
idaku2@gmail.com
Guest
Posts: n/a
 
      05-14-2007
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

 
Reply With Quote
 
 
 
 
TobiMc3@gmail.com
Guest
Posts: n/a
 
      05-14-2007
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



 
Reply With Quote
 
 
 
 
visionset
Guest
Posts: n/a
 
      05-14-2007

<> wrote in message
news: ups.com...
> 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,


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()?
>


--
Mike W


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
class design/ design pattern question Bartholomew Simpson C++ 2 06-12-2007 08:51 PM
Class design/design pattern resources TomTom MCSD 2 10-09-2004 07:38 AM
OO design in servlet design question dave Java 5 07-17-2004 12:58 PM
Xilinx Schematic design vs VHDL code design ZackS VHDL 5 07-09-2004 07:51 AM
Looking for help/resources on Writing a nice detailed design / tech design for vb.net code SpamProof Java 3 12-01-2003 06:06 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57