The Parameter Object pattern groups related method parameters into one small, immutable object. It replaces crowded signatures with a named input whose fields communicate intent and reduce mistakes when several parameters share a type. section 4.2.2
From loose parameters to a meaningful input
Instead of passing separate weight and height values to BMI logic, pass a PhysicalProfile or another focused carrier. Java records such as WeightInPounds, HeightInInches, and PhysicalProfile make units, relationships, and immutability visible at the call site. The same modeling approach produces AgeBmiKey for combined age-and-category lookup keys. section 4.2.2
Listing 4.3 Defining a clear and type-safe physical profile
public record Age(int value) {
public Age {
if (value < 0 || value > 150) {
throw new IllegalArgumentException("Age must " +
"be between 0 and 150.");
}
}
}
public record HeightInInches(double value) {
public HeightInInches {
if (value <= 0) {
throw new IllegalArgumentException("Height must be greater " +
"than 0 inches.");
}
}
}
public record WeightInPounds(double value) {
public WeightInPounds {
if (value <= 0) {
throw new IllegalArgumentException("Weight must be greater " +
"than 0 pounds.");
}
}
}
public record PhysicalProfile(Gender gender,
Age age,
WeightInPounds weight,
HeightInInches height) {
}
Inspect a type-safe record-based carrier that validates its values and groups the physical profile's related inputs. section 4.2.2
