Class Material

java.lang.Object
com.university.bookstore.model.Material
All Implemented Interfaces:
Comparable<Material>
Direct Known Subclasses:
AudioBook, EBook, Magazine, MaterialDecorator, PrintedBook, VideoMaterial

public abstract class Material extends Object implements Comparable<Material>
Abstract base class representing any material in the store inventory. Demonstrates abstraction and inheritance in OOP design.

This class provides common properties and behavior for all materials including books, magazines, audio, and video content.

Since:
2024-09-15
Version:
2.0
Author:
Navid Mohaghegh
  • Method Details

    • getCreator

      public abstract String getCreator()
      Abstract method to get the creator/author/artist of the material. Implementation varies by material type.
      Returns:
      the creator's name
    • getDisplayInfo

      public abstract String getDisplayInfo()
      Abstract method to get a formatted display string. Each material type should provide its own formatting.
      Returns:
      formatted display string
    • getDiscountedPrice

      public final double getDiscountedPrice()
      Template method for calculating discounted price. Subclasses can override getDiscountRate() to customize.
      Returns:
      discounted price
    • getDiscountRate

      public double getDiscountRate()
      Hook method for discount rate. Default is no discount. Subclasses can override to provide type-specific discounts.
      Returns:
      discount rate between 0.0 and 1.0
    • getId

      public String getId()
    • getTitle

      public String getTitle()
    • getPrice

      public double getPrice()
    • getYear

      public int getYear()
    • getType

      public Material.MaterialType getType()
    • compareTo

      public int compareTo(Material other)
      Compares materials by title for natural ordering.
      Specified by:
      compareTo in interface Comparable<Material>
    • equals

      public boolean equals(Object obj)
      Materials are equal if they have the same ID.
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object