CO[R]RECT: [R]ange

Learn the importance of range and the use of constraints in writing tests.

When we use Java’s built-in variables, we often get far more capacity than we need. If we represent a person’s age using an int, we’d be safe for at least a couple of million centuries. Inevitably, things will go wrong, and we’ll end up with a person a few times older than Methuselah, or a backward time traveler with a negative age.

Excessive use of primitive datatypes is a code smell known as a primitive obsession. A benefit of an object-oriented language like Java is that it lets us define our own custom abstractions in the form of classes.

In order to understand the importance of range, we will look into the examples of circles and rectangles.

Get hands-on with 1200+ tech skills courses.