Interface MaterialStore
- All Known Subinterfaces:
ModernMaterialStore
- All Known Implementing Classes:
ConcurrentMaterialStore,MaterialStoreImpl,ModernConcurrentMaterialStore
BookstoreAPI, this interface is extensible to other types of materials.
The Interface Segregation Principle (ISP) states that clients should not be forced to depend on interfaces they do not use. In practice, this means designing smaller, more focused interfaces rather than large, monolithic ones. For example, instead of creating a single Machine interface with methods like print(), scan(), and fax(), which every implementation must support, ISP encourages splitting these into multiple role-specific interfaces (Printer, Scanner, FaxMachine). This ensures that implementing classes only provide the functionality relevant to them, leading to higher cohesion, reduced coupling, and easier maintenance. ISP directly combats the rigidity and fragility that arise when changes in unused methods propagate across unrelated parts of the system.
The Dependency Inversion Principle (DIP) requires that high-level modules depend on abstractions, not concrete implementations. Instead of having business logic directly tied to low-level details (like a specific database driver or logging mechanism), DIP advocates for using interfaces or abstract classes as boundaries. For instance, a PaymentService should rely on a PaymentProcessor interface rather than a hardcoded StripeProcessor. This allows developers to substitute implementations without altering higher-level policies, supporting testability, scalability, and adaptability to new technologies. By inverting the dependency direction, DIP ensures that both high- and low-level modules evolve independently, fostering loosely coupled, extensible architectures.
This interface extends the concept of a bookstore to handle various types of materials using polymorphism.
- Since:
- 2024-09-15
- Version:
- 2.0
- Author:
- Navid Mohaghegh
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic classStatistics class for inventory analysis. -
Method Summary
Modifier and TypeMethodDescriptionbooleanaddMaterial(Material material) Adds a material to the store inventory.voidClears all materials from the store.filterMaterials(Predicate<Material> predicate) Filters materials by a custom predicate.findByCreators(String... creators) Finds materials by multiple creators (OR condition).Finds a material by its ID.findRecentMaterials(int years) Finds materials published in the last N years.findWithPredicate(Predicate<Material> condition) Finds materials with custom filtering using predicate.Gets all materials (unsorted).Gets all materials sorted by title.Gets inventory statistics.getMaterialsByPriceRange(double minPrice, double maxPrice) Gets materials within a price range.Gets all materials of a specific type.getMaterialsByYear(int year) Gets materials published/released in a specific year.Gets all materials that implement the Media interface.getSorted(Comparator<Material> comparator) Gets materials sorted by custom comparator.doubleCalculates total discounted inventory value.doubleCalculates total inventory value.booleanisEmpty()Checks if the inventory is empty.removeMaterial(String id) Removes a material by its ID.searchByCreator(String creator) Searches materials by creator (author/director/publisher).searchByTitle(String title) Searches materials by title (case-insensitive partial match).intsize()Gets the number of materials in inventory.
-
Method Details
-
addMaterial
Adds a material to the store inventory.- Parameters:
material- the material to add- Returns:
- true if added successfully, false if duplicate ID
-
removeMaterial
-
findById
-
searchByTitle
-
searchByCreator
-
getMaterialsByType
Gets all materials of a specific type. Demonstrates polymorphic filtering.- Parameters:
type- the material type- Returns:
- list of materials of the specified type
-
getMediaMaterials
-
filterMaterials
-
findRecentMaterials
-
findByCreators
-
findWithPredicate
-
getSorted
Gets materials sorted by custom comparator.- Parameters:
comparator- the sorting comparator- Returns:
- sorted list of materials
-
getMaterialsByPriceRange
-
getMaterialsByYear
-
getAllMaterialsSorted
-
getAllMaterials
-
getTotalInventoryValue
double getTotalInventoryValue()Calculates total inventory value.- Returns:
- sum of all material prices
-
getTotalDiscountedValue
double getTotalDiscountedValue()Calculates total discounted inventory value. Uses polymorphic discount calculation.- Returns:
- sum of all discounted prices
-
getInventoryStats
MaterialStore.InventoryStats getInventoryStats()Gets inventory statistics.- Returns:
- statistics object with counts and averages
-
clearInventory
void clearInventory()Clears all materials from the store. -
size
int size()Gets the number of materials in inventory.- Returns:
- material count
-
isEmpty
boolean isEmpty()Checks if the inventory is empty.- Returns:
- true if no materials in inventory
-