Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying Refactoring in Java
  • Table Of Contents Toc
  • Feedback & Rating feedback
Refactoring in Java

Refactoring in Java

By : Stefano Violetta
5 (1)
close
close
Refactoring in Java

Refactoring in Java

5 (1)
By: Stefano Violetta

Overview of this book

Refactoring in Java serves as an indispensable guide to enhancing your codebase’s quality and maintainability. The book begins by helping you get to grips with refactoring fundamentals, including cultivating good coding habits and identifying red flags. You’ll explore testing methodologies, essential refactoring techniques, and metaprogramming, as well as designing a good architecture. The chapters clearly explain how to refactor and improve your code using real-world examples and proven techniques. Part two equips you with the ability to recognize code smells, prioritize tasks, and employ automated refactoring tools, testing frameworks, and code analysis tools. You’ll discover best practices to ensure efficient code improvement so that you can navigate complexities with ease. In part three, the book focuses on continuous learning, daily practices enhancing coding proficiency, and a holistic view of the architecture. You’ll get practical tips to mitigate risks during refactoring, along with guidance on measuring impact to ensure that you become an efficient software craftsperson. By the end of this book, you’ll be able to avoid unproductive programming or architecturing, detect red flags, and propose changes to improve the maintainability of your codebase.
Table of Contents (15 chapters)
close
close
1
Part 1: Introduction to Refactoring
4
Part 2: Essence of Refactoring and Good Code
Free Chapter
10
Part 3: Further Learning

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...

Unlock full access

Continue reading for free

A Packt free trial gives you instant online access to our library of over 7000 practical eBooks and videos, constantly updated with the latest in tech
bookmark search playlist download font-size

Change the font size

margin-width

Change margin width

day-mode

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Delete Bookmark

Modal Close icon
Are you sure you want to delete it?
Cancel
Yes, Delete

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY