Prerequisites
Core Concepts
The Problem
Businesses constantly face the question: “How does execution compare to the plan?”- Production: Did we produce what we planned?
- Payments: Did customers pay according to schedule?
- Deliveries: Were deliveries on time?
The Solution
The module provides:- Immutable Plan - A snapshot of what should happen
- Execution History - What actually happened
- Tolerance Strategy - Rules for acceptable deviations
- Delta Calculator - Computes matched/unmatched items
- Statistics - Summary metrics (match rate, deviations, etc.)
Key Principle: Separation
See Bad Implementation Anti-Pattern for what NOT to do.Step-by-Step Tutorial
import com.softwarearchetypes.planvsexecution.productionanalysis.*;
import com.softwarearchetypes.planvsexecution.productionanalysis.delta.*;
import com.softwarearchetypes.planvsexecution.productionanalysis.tolerance.*;
import java.util.List;
ProductionAnalysisFacade facade = new ProductionAnalysisFacade();
ProductionPlan plan = ProductionPlan.of(List.of(
PlannedProduction.of("WIDGET-A", 1000),
PlannedProduction.of("WIDGET-B", 1500),
PlannedProduction.of("WIDGET-C", 800)
));
System.out.println("Plan created for 3 products");
System.out.println("Total planned: " +
(1000 + 1500 + 800) + " units");
The plan is immutable. You can create multiple plans and compare the same execution against all of them.
List<ActualProduction> actual = List.of(
ActualProduction.of("WIDGET-A", 998), // 2 units short
ActualProduction.of("WIDGET-B", 1520), // 20 units over
ActualProduction.of("WIDGET-C", 800) // Perfect match
);
System.out.println("Actual production recorded");
// Exact matching: no tolerance
ToleranceStrategy exactMatch = ToleranceBuilder.exact();
// Lenient: accept ±5% or ±10 units (whichever is larger)
ToleranceStrategy lenient = ToleranceBuilder.quantityTolerance(
5.0, // 5% deviation
10 // or 10 units absolute
);
// Strict comparison
DeltaResult strictResult = facade.analyze(plan, actual, exactMatch);
System.out.println("=== Strict Analysis ===");
System.out.println("Matched: " + strictResult.matched().size());
System.out.println("Unmatched planned: " + strictResult.unmatchedPlanned().size());
System.out.println("Perfect match: " + strictResult.isPerfectMatch());
// Lenient comparison
DeltaResult lenientResult = facade.analyze(plan, actual, lenient);
System.out.println("\n=== Lenient Analysis ===");
System.out.println("Matched: " + lenientResult.matched().size());
System.out.println("Unmatched planned: " + lenientResult.unmatchedPlanned().size());
System.out.println("Perfect match: " + lenientResult.isPerfectMatch());
DeltaStatistics stats = lenientResult.statistics();
System.out.println("\n=== Statistics ===");
System.out.println("Match rate: " +
String.format("%.1f%%", lenientResult.matchRate() * 100));
System.out.println("Under-produced: " +
stats.totalUnderProducedQuantity() + " units");
System.out.println("Over-produced: " +
stats.totalOverProducedQuantity() + " units");
System.out.println("Net difference: " +
stats.netQuantityDifference() + " units");
ProductionPlan bigOrder = ProductionPlan.of(List.of(
PlannedProduction.of("WIDGET-A", 5000)
));
// Produced in 3 separate batches
List<ActualProduction> splitProduction = List.of(
ActualProduction.of("WIDGET-A", 2100),
ActualProduction.of("WIDGET-A", 1950),
ActualProduction.of("WIDGET-A", 1000)
);
ToleranceStrategy tolerance = ToleranceBuilder.quantityTolerance(5.0, 50);
DeltaResult result = facade.analyze(bigOrder, splitProduction, tolerance);
if (result.matched().size() > 0) {
ProductionMatch match = result.matched().get(0);
System.out.println("Planned: " + match.planned().quantity());
System.out.println("Actual batches: " + match.actual().size());
System.out.println("Total produced: " + match.totalProducedQuantity());
}
Payment Schedule Analysis
Analyze customer payments against installment schedule:Partial Payments Pattern
Handle customers paying in multiple installments:What-If Analysis: Compare Multiple Plans
The key advantage: compare same execution against different plans.This is impossible if plan and execution are in the same mutable entity! See Bad Implementation for details.
Configurable Plans with Modification Rules
For advanced scenarios, create plans that automatically adjust based on execution:Complete Production Analysis Example
Common Patterns
Pattern: Grade Execution Performance
Pattern: Alert on Critical Misses
Pattern: Trend Analysis
Next Steps
- Anti-patterns: See Bad Implementation to learn what NOT to do
- Resolution Mismatch: See Resolution Mismatch for handling different granularities
- Advanced Tolerance: Learn about custom tolerance strategies in the API docs
The Plan vs Execution module enables combinatoric analysis: M plans × N executions = M×N deltas. This is only possible with immutable, separated data.
