Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

how to design this in OOP ?

 
Ranch Hand
Posts: 798
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 160
IntelliJ IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 overall mission is to change the world. When you've done that, then you can read this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic