Overview
Batch describes a set of ProductInstances of a specific ProductType that are tracked together, usually for quality control purposes.
Package: com.softwarearchetypes.product
Source: /product/src/main/java/com/softwarearchetypes/product/Batch.java:21
When to Use
Batch tracking is appropriate when:- Individual instance identity is unimportant, but batch origin matters
- Need to track manufacturing/quality control information
- Common with foodstuffs, chemicals, and manufactured goods
Constructor
Batch.builder() to create instances.
Unique identifier for this batch
Human-readable batch name
The ProductType this batch belongs to
Total quantity in this batch. Unit must match ProductType’s preferred unit.
When the batch was produced (optional)
Sell-by date (optional)
Use-by date (optional)
Best-before date (optional)
Starting serial number in range (optional)
Ending serial number in range (optional)
Additional comments about the batch (optional)
Builder Pattern
builder
A new Builder instance
Accessor Methods
id
The batch identifier
name
The batch name
batchOf
The product identifier
quantityInBatch
The batch quantity
dateProduced
The production date, or empty if not set
sellBy
The sell-by date, or empty if not set
useBy
The use-by date, or empty if not set
bestBefore
The best-before date, or empty if not set
startSerialNumber
The start serial number, or empty if not set
endSerialNumber
The end serial number, or empty if not set
comments
The comments, or empty if not set
Builder Methods
TheBuilder class provides a fluent interface for constructing Batch instances.
id
The batch identifier
This builder for chaining
name
The batch name
This builder for chaining
batchOf
The product type
This builder for chaining
quantityInBatch
The batch quantity
This builder for chaining
dateProduced
The production date
This builder for chaining
sellBy
The sell-by date
This builder for chaining
useBy
The use-by date
This builder for chaining
bestBefore
The best-before date
This builder for chaining
startSerialNumber
The start serial number
This builder for chaining
endSerialNumber
The end serial number
This builder for chaining
comments
Additional comments
This builder for chaining
build
The constructed Batch
IllegalArgumentException if:
- Required fields are missing
- Quantity unit doesn’t match ProductType’s preferred unit
Validation
The Batch constructor validates that:- The quantity unit matches the ProductType’s preferred unit
- All required fields are provided
