# 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`

public abstract class MaterialDecorator extends Material
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

  Constructors
  Constructor
  Description
  `MaterialDecorator(Material material)`
  Creates a new material decorator wrapping the specified material.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `boolean`
  `equals(Object obj)`
  Materials are equal if they have the same ID.
  `Material`
  `getBaseMaterial()`
  Gets the base material (unwraps all decorators).
  `String`
  `getCreator()`
  Abstract method to get the creator/author/artist of the material.
  `Material`
  `getDecoratedMaterial()`
  Gets the decorated material.
  `int`
  `getDecoratorCount()`
  Gets the number of decorators applied to this material.
  `double`
  `getDiscountRate()`
  Hook method for discount rate.
  `String`
  `getDisplayInfo()`
  Abstract method to get a formatted display string.
  `boolean`
  `hasDecorators()`
  Checks if this material has any decorators applied.
  `int`
  `hashCode()`
  `String`
  `toString()`

  ### Methods inherited from class com.university.bookstore.model.Material

  `compareTo, getDiscountedPrice, getId, getPrice, getTitle, getType, getYear`

  ### Methods inherited from class java.lang.Object

  `getClass, notify, notifyAll, wait, wait, wait`

- ## Constructor Details

  - ### MaterialDecorator

    public MaterialDecorator(Material material)
    Creates a new material decorator wrapping the specified material.
    Parameters:
      `material` - the material to decorate
    Throws:
      `IllegalArgumentException` - if material is null

- ## Method Details

  - ### getCreator

    public String getCreator()
    Description copied from class: `Material`
    Abstract method to get the creator/author/artist of the material. Implementation varies by material type.
    Specified by:
      `getCreator` in class `Material`
    Returns:
      the creator's name

  - ### getDisplayInfo

    public String getDisplayInfo()
    Description copied from class: `Material`
    Abstract method to get a formatted display string. Each material type should provide its own formatting.
    Specified by:
      `getDisplayInfo` in class `Material`
    Returns:
      formatted display string

  - ### getDiscountRate

    public double getDiscountRate()
    Description copied from class: `Material`
    Hook method for discount rate. Default is no discount. Subclasses can override to provide type-specific discounts.
    Overrides:
      `getDiscountRate` in class `Material`
    Returns:
      discount rate between 0.0 and 1.0

  - ### getDecoratedMaterial

    public Material getDecoratedMaterial()
    Gets the decorated material.
    Returns:
      the wrapped material

  - ### getBaseMaterial

    public Material 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

    public boolean equals(Object obj)
    Description copied from class: `Material`
    Materials are equal if they have the same ID.
    Overrides:
      `equals` in class `Material`

  - ### hashCode

    public int hashCode()
    Overrides:
      `hashCode` in class `Material`

  - ### toString

    public String toString()
    Overrides:
      `toString` in class `Material`