Using enums instead of constants
At this point, we have seen some of the main refactoring techniques discussed in the literature. Now, we move on to a final section where we allow ourselves to give you a couple of tips on how to better organize your code design. These may seem trivial, but they often lead to considerable annoyance. The first tip, as the title of this section suggests, concerns the excessive use of constants (a thorough study based solely on my perception and experience undoubtedly shows that these constants will be strings 99% of the time).
Let’s suppose we have the following class:
public class Itinerary { private String transportType; private String cabinClass; //getters and setters }
In another class, we defined the following constants:
private static final String FLIGHT = "FLIGHT"; private static final String TRAIN = "TRAIN"; private static final String...