aspose file tools
The moose likes Java in General and the fly likes How to get total Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Badass: Making Users Awesome this week in the Game Development forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to get total" Watch "How to get total" New topic

How to get total

Kasparov Patel
Ranch Hand

Joined: Jan 23, 2012
Posts: 40
Hello Friends,

Please find my code as follow:

I am just trying to implement decorator pattern, but I am not getting how can I get method.

I would appreciate if any one can help me.

Thanking You,
Tony Docherty

Joined: Aug 07, 2007
Posts: 2629
I'm not sure of your reasons for using the decorator pattern here but if Discount and or Reduction are supposed to be your decorator classes then you need to pass an instance of the object they are supposed to decorate into the constructor and then in the getPrice() method you would call getPrice() on the object which you are decorating. Currently your Discount and Reduction classes recursively call their own getPrice() method with no way of exiting the recursive calls.
It is sorta covered in the JavaRanch Style Guide.
subject: How to get total