Class MaterialEnhancementService
java.lang.Object
com.university.bookstore.decorator.MaterialEnhancementService
Service for managing material enhancements using the Decorator pattern.
Provides methods to apply various decorators to materials and create enhancement packages.
This service demonstrates the Decorator pattern in action by providing a high-level interface for dynamically adding features to materials.
- Since:
- 2024-09-15
- Version:
- 3.0
- Author:
- Navid Mohaghegh
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddDigitalAnnotations(Material material) Adds digital annotations to a material.addExpeditedDelivery(Material material, int deliveryDays) Adds expedited delivery to a material.addGiftWrapping(Material material, String style) Adds gift wrapping to a material.doublecalculateEnhancementCost(Material original, Material enhanced) Calculates the total enhancement cost for a material.createDigitalPackage(Material material) Creates a digital package with digital annotations (for e-books only).createGiftPackage(Material material, String giftStyle, int deliveryDays) Creates a gift package with gift wrapping and expedited delivery.createPremiumPackage(Material material, String giftStyle, int deliveryDays) Creates a premium package with multiple enhancements.getBaseMaterial(Material material) Gets the base material (unwraps all decorators).doublegetBasePrice(Material material) Gets the base price of a material (without decorators).intgetEnhancementCount(Material material) Gets the number of decorators applied to a material.getEnhancementSummary(Material material) Gets a summary of enhancements applied to a material.booleanhasEnhancement(Material material, Class<? extends MaterialDecorator> enhancementType) Checks if a material has a specific type of enhancement.booleanhasEnhancements(Material material) Checks if a material has any enhancements applied.toString()
-
Constructor Details
-
MaterialEnhancementService
public MaterialEnhancementService()
-
-
Method Details
-
addGiftWrapping
Adds gift wrapping to a material.- Parameters:
material- the material to enhancestyle- the wrapping style- Returns:
- the enhanced material with gift wrapping
- Throws:
IllegalArgumentException- if material or style is null
-
addExpeditedDelivery
Adds expedited delivery to a material.- Parameters:
material- the material to enhancedeliveryDays- the number of days for delivery- Returns:
- the enhanced material with expedited delivery
- Throws:
IllegalArgumentException- if material is null or deliveryDays is invalid
-
addDigitalAnnotations
Adds digital annotations to a material.- Parameters:
material- the material to enhance- Returns:
- the enhanced material with digital annotations
- Throws:
IllegalArgumentException- if material is null
-
createPremiumPackage
Creates a premium package with multiple enhancements.- Parameters:
material- the material to enhancegiftStyle- the gift wrapping styledeliveryDays- the number of days for delivery- Returns:
- the enhanced material with premium package
- Throws:
IllegalArgumentException- if material is null or parameters are invalid
-
createGiftPackage
Creates a gift package with gift wrapping and expedited delivery.- Parameters:
material- the material to enhancegiftStyle- the gift wrapping styledeliveryDays- the number of days for delivery- Returns:
- the enhanced material with gift package
-
createDigitalPackage
-
calculateEnhancementCost
-
getEnhancementSummary
-
getBasePrice
Gets the base price of a material (without decorators).- Parameters:
material- the material to analyze- Returns:
- the base price
-
hasEnhancements
Checks if a material has any enhancements applied.- Parameters:
material- the material to check- Returns:
- true if enhancements are applied
-
getEnhancementCount
Gets the number of decorators applied to a material.- Parameters:
material- the material to analyze- Returns:
- the decorator count
-
getBaseMaterial
-
hasEnhancement
public boolean hasEnhancement(Material material, Class<? extends MaterialDecorator> enhancementType) Checks if a material has a specific type of enhancement.- Parameters:
material- the material to checkenhancementType- the type of enhancement to look for- Returns:
- true if the enhancement is applied
-
toString
-