...
Code Block | ||
---|---|---|
| ||
protected int getVolumePackage(int weight) { try { if (length <= 0 || width <= 0 || height <= 0 || length > MAX_DIMENSION || width > MAX_DIMENSION || height > MAX_DIMENSION || weight <= 0 || weight > 20) { throw new IllegalArgumentException(); // Validate first } } catch (Throwable t) { MyExceptionReporter mer = new MyExceptionReporter(); mer.report(t); // Sanitize return -1; } length += PADDING; width += PADDING; height += PADDING; int volume = length * width * height; length -= PADDING; width -= PADDING; height -= PADDING; return volume; } |
Compliant Solution (
...
Unmodified Object)
This compliant solution avoids the need to modify the object. Consequently, the fields The object's state cannot be violated made inconsistent and rollback is consequently unnecessary. This approach is preferred to solutions which modify the object but may be infeasible for complex code.
...