Class MaterialFactory

java.lang.Object
com.university.bookstore.factory.MaterialFactory

public class MaterialFactory extends Object
Factory class for creating Material instances. Demonstrates the Factory pattern by providing a centralized way to create different types of materials without exposing their constructors directly.

This factory supports creating all material types including the new EBook class, with proper validation and error handling.

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

    • MaterialFactory

      public MaterialFactory()
  • Method Details

    • createMaterial

      public static Material createMaterial(String type, Map<String,Object> properties)
      Creates a Material instance based on the specified type and properties.
      Parameters:
      type - the material type
      properties - map of properties required for the material
      Returns:
      the created Material instance
      Throws:
      IllegalArgumentException - if type is null or properties are invalid
      NullPointerException - if required properties are missing