Interface Item
- All Known Implementing Classes:
StoreBulkItem, StoreItem
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 TypeMethodDescriptioncalculateTotal(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.getName()Returns the name for this Item.getPrice()Returns the unit price for this Item.
-
Method Details
-
getName
-
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
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 fortheUseMembershipPricing- 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
-