Class DiscountHandler

java.lang.Object
com.university.bookstore.chain.DiscountHandler
Direct Known Subclasses:
DirectorHandler, ManagerHandler, VPHandler

public abstract class DiscountHandler extends Object
Abstract base class for discount approval handlers in the Chain of Responsibility pattern. Defines the interface for handling discount requests and managing the chain.

This class provides the basic structure for the chain of responsibility, allowing handlers to either process requests or pass them to the next handler.

Since:
2024-09-15
Version:
3.0
Author:
Navid Mohaghegh
  • Constructor Details

    • DiscountHandler

      public DiscountHandler()
  • Method Details

    • setNext

      public void setNext(DiscountHandler nextHandler)
      Sets the next handler in the chain.
      Parameters:
      nextHandler - the next handler
    • getNext

      public DiscountHandler getNext()
      Gets the next handler in the chain.
      Returns:
      the next handler
    • handleRequest

      public abstract void handleRequest(DiscountRequest request)
      Handles a discount request. Subclasses must implement this method to define their approval logic.
      Parameters:
      request - the discount request to handle
    • getHandlerName

      public abstract String getHandlerName()
      Gets the name of this handler for identification purposes.
      Returns:
      the handler name
    • getMaxDiscount

      public abstract double getMaxDiscount()
      Gets the maximum discount this handler can approve.
      Returns:
      the maximum discount rate (0.0 to 1.0)
    • canApprove

      public boolean canApprove(double discount)
      Checks if this handler can approve the given discount amount.
      Parameters:
      discount - the discount rate to check
      Returns:
      true if this handler can approve the discount
    • getChainLength

      public int getChainLength()
      Gets the chain length from this handler to the end.
      Returns:
      the chain length
    • getHandlerInfo

      public String getHandlerInfo()
      Gets information about this handler and the chain.
      Returns:
      handler information
    • toString

      public String toString()
      Overrides:
      toString in class Object