File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/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
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to get total" Watch "How to get total" New topic
Author

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,
Kasparov
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2173
    
  47
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
 
Similar Threads
Abstract method query
modifier for enum
Abstract inner class in the abstract outer class
static with abstract
Legal Method Declarations II