Interface Item

All Known Implementing Classes:
StoreBulkItem, StoreItem

public sealed interface Item permits StoreItem, StoreBulkItem
Represents a single item for sale in the bookstore.

This interface defines the contract for all items, requiring them to know how to calculate their own total price (Information Expert pattern). Items handle their own pricing logic, removing the need for external code to know about bulk pricing or other pricing strategies.

This is a sealed interface, meaning only the explicitly permitted types can implement it. This creates a closed hierarchy where the compiler knows all possible item types, enabling exhaustive pattern matching and preventing unexpected extensions.

Version:
Winter 2026
Author:
Charles Bryan
  • Method Summary

    Modifier and Type
    Method
    Description
    calculateTotal(int theQuantity, boolean theUseMembershipPricing)
    Calculates the total price for the given quantity of this item.
    Returns a formatted description of this item suitable for display in a GUI.
    Returns the name for this Item.
    Returns the unit price for this Item.
  • Method Details

    • getName

      String getName()
      Returns the name for this Item.
      Returns:
      the name for this Item
    • getPrice

      BigDecimal getPrice()
      Returns the unit price for this Item. This is the price for a single unit, used for display.
      Returns:
      the unit price for this Item
    • calculateTotal

      BigDecimal calculateTotal(int theQuantity, boolean theUseMembershipPricing)
      Calculates the total price for the given quantity of this item.

      The useMembershipPricing parameter allows items to apply membership discounts. Currently, only bulk items apply discounts when this is true, but the design allows for future expansion (e.g., percentage discounts on all items for members).

      Parameters:
      theQuantity - the quantity to calculate the total for
      theUseMembershipPricing - true if membership pricing should be applied
      Returns:
      the total price for the given quantity
      Throws:
      IllegalArgumentException - if theQuantity is negative
    • getFormattedDescription

      String getFormattedDescription()
      Returns a formatted description of this item suitable for display in a GUI.

      This method provides a human-readable representation of the item including its name, price, and (for bulk items) bulk pricing information. This is distinct from toString() which is intended for debugging purposes.

      Format examples: - Simple item: "Computer Science Pen, $2.00" - Bulk item: "'Java Rules!' button, $0.95 (10 for $5.00)"

      Returns:
      a formatted string suitable for display to end users