Class DiscountHandler
java.lang.Object
com.university.bookstore.chain.DiscountHandler
- Direct Known Subclasses:
DirectorHandler,ManagerHandler,VPHandler
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleancanApprove(double discount) Checks if this handler can approve the given discount amount.intGets the chain length from this handler to the end.Gets information about this handler and the chain.abstract StringGets the name of this handler for identification purposes.abstract doubleGets the maximum discount this handler can approve.getNext()Gets the next handler in the chain.abstract voidhandleRequest(DiscountRequest request) Handles a discount request.voidsetNext(DiscountHandler nextHandler) Sets the next handler in the chain.toString()
-
Constructor Details
-
DiscountHandler
public DiscountHandler()
-
-
Method Details
-
setNext
Sets the next handler in the chain.- Parameters:
nextHandler- the next handler
-
getNext
-
handleRequest
Handles a discount request. Subclasses must implement this method to define their approval logic.- Parameters:
request- the discount request to handle
-
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
Gets information about this handler and the chain.- Returns:
- handler information
-
toString
-