Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / May 2007

Tip: Looking for answers? Try searching our database.

[Newbie] design question

Thread view: 
idaku2@gmail.com - 14 May 2007 16:49 GMT
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



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.