CO[R]RECT: [R]ange
When you use Java’s built-in types for variables, you often get far more capacity than you need. If you represent a person’s age using an int, you’d be safe for at least a couple million more centuries. Inevitably, things will go wrong, and you’ll end up with a person a few times older than Methuselah, or a backward time traveler—someone with a negative age.
Excessive use of primitive datatypes is a code smell known as primitive obsession. A benefit of an object-oriented language like Java is that it lets you define your own custom abstractions in the form of classes.
A circle has only 360 degrees. Rather than store the direction of travel as a native type, create a class named Bearing that encapsulates the direction along ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access