• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to get total

 
Kasparov Patel
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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,
Kasparov
 
Tony Docherty
Bartender
Posts: 2965
59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic