Class MaterialDecorator
java.lang.Object
com.university.bookstore.model.Material
com.university.bookstore.decorator.MaterialDecorator
- All Implemented Interfaces:
Comparable<Material>
- Direct Known Subclasses:
DigitalAnnotationDecorator,ExpeditedDeliveryDecorator,GiftWrappingDecorator
Abstract base class for material decorators in the Decorator pattern.
Provides a common interface for decorating materials with additional features.
This class implements the Material interface and delegates all operations to the wrapped material, allowing subclasses to override specific methods to add new functionality without modifying the original material classes.
- Since:
- 2024-09-15
- Version:
- 3.0
- Author:
- Navid Mohaghegh
-
Nested Class Summary
Nested classes/interfaces inherited from class com.university.bookstore.model.Material
Material.MaterialType -
Constructor Summary
ConstructorsConstructorDescriptionMaterialDecorator(Material material) Creates a new material decorator wrapping the specified material. -
Method Summary
Modifier and TypeMethodDescriptionbooleanMaterials are equal if they have the same ID.Gets the base material (unwraps all decorators).Abstract method to get the creator/author/artist of the material.Gets the decorated material.intGets the number of decorators applied to this material.doubleHook method for discount rate.Abstract method to get a formatted display string.booleanChecks if this material has any decorators applied.inthashCode()toString()
-
Constructor Details
-
MaterialDecorator
Creates a new material decorator wrapping the specified material.- Parameters:
material- the material to decorate- Throws:
IllegalArgumentException- if material is null
-
-
Method Details
-
getCreator
Description copied from class:MaterialAbstract method to get the creator/author/artist of the material. Implementation varies by material type.- Specified by:
getCreatorin classMaterial- Returns:
- the creator's name
-
getDisplayInfo
Description copied from class:MaterialAbstract method to get a formatted display string. Each material type should provide its own formatting.- Specified by:
getDisplayInfoin classMaterial- Returns:
- formatted display string
-
getDiscountRate
public double getDiscountRate()Description copied from class:MaterialHook method for discount rate. Default is no discount. Subclasses can override to provide type-specific discounts.- Overrides:
getDiscountRatein classMaterial- Returns:
- discount rate between 0.0 and 1.0
-
getDecoratedMaterial
-
getBaseMaterial
Gets the base material (unwraps all decorators).- Returns:
- the original material without any decorations
-
getDecoratorCount
public int getDecoratorCount()Gets the number of decorators applied to this material.- Returns:
- the decorator count
-
hasDecorators
public boolean hasDecorators()Checks if this material has any decorators applied.- Returns:
- true if decorators are applied
-
equals
-
hashCode
-
toString
-