Class Material
java.lang.Object
com.university.bookstore.model.Material
- All Implemented Interfaces:
Comparable<Material>
- Direct Known Subclasses:
AudioBook,EBook,Magazine,MaterialDecorator,PrintedBook,VideoMaterial
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumEnumeration of material types for polymorphic behavior. -
Method Summary
Modifier and TypeMethodDescriptionintCompares materials by title for natural ordering.booleanMaterials are equal if they have the same ID.abstract StringAbstract method to get the creator/author/artist of the material.final doubleTemplate method for calculating discounted price.doubleHook method for discount rate.abstract StringAbstract method to get a formatted display string.getId()doublegetPrice()getTitle()getType()intgetYear()inthashCode()toString()
-
Method Details
-
getCreator
Abstract method to get the creator/author/artist of the material. Implementation varies by material type.- Returns:
- the creator's name
-
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
-
getTitle
-
getPrice
public double getPrice() -
getYear
public int getYear() -
getType
-
compareTo
Compares materials by title for natural ordering.- Specified by:
compareToin interfaceComparable<Material>
-
equals
-
hashCode
-
toString
-