This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes how to design this in OOP ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "how to design this in OOP ?" Watch "how to design this in OOP ?" New topic
Author

how to design this in OOP ?

Edward Chen
Ranch Hand

Joined: Dec 23, 2003
Posts: 798
When browsing Amazon, it will give a special price to a combination of books, for example, Book A price is $10, Book B is $20, but Book A + Book B will cost a special discount price, say $25. In OOP design, how to achieve this ?

My thinking is , we could do

In this way, single Book will be a special case, its components is null (zero).

Or has another way to design ?

Thanks.
Riaan Nel
Ranch Hand

Joined: Apr 23, 2009
Posts: 160

I'd rather have something like a Combination class which contains a number of books. The combination class could then have a price which is calculated based on the price of each book within the combination.

P.S. Why are you using the Double wrapper class instead of the double primitive for your price variable? Also, just to stick to the standard way of doing things, I'd make the components and price properties of the Book class private and write getters and setters for them.


"The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man." - George Bernard Shaw
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: how to design this in OOP ?
 
It's not a secret anymore!