Code Refactoring for Java

This course deals with the concept of refactoring as a way of preventing software rot. It describes various “smells” indicating that code needs refactoring, explains which refactoring types best suit specific situations, and describes the work of refactoring in detail through THE analysis of concrete, real-life cases.
  • duration 24 hours
  • Language English
  • format Online
duration
24 hours
location
Online
Language
English
Code
DEV-006_JVA
price
€ 600 *

Available sessions

To be determined



Training for 7-8 or more people?
Customize trainings for your specific needs

Description

In the relentless pursuit of software excellence, the specter of "software rot" looms ominously, threatening the integrity and effectiveness of even the most meticulously crafted codebases. However, armed with a powerful arsenal of refactoring techniques, developers can stem the tide of decay and fortify their code against the ravages of time. Welcome to a comprehensive exploration of Code Refactoring for Java, where we delve deep into the art and science of revitalizing and rejuvenating code to prevent software rot.

 

This immersive course embarks on a journey through the labyrinthine world of code smells and refactoring strategies, equipping participants with the knowledge, skills, and insights needed to breathe new life into aging codebases. We begin by identifying the telltale signs of code decay and exploring a myriad of common "smells" that serve as red flags for potential refactoring opportunities. From bloated methods and tangled class hierarchies to duplicated code and convoluted conditional expressions, participants will learn to recognize these symptoms and diagnose the underlying issues with precision.

 

With a firm understanding of code smells in hand, we proceed to dissect the anatomy of refactoring itself, exploring a diverse array of refactoring types tailored to specific code scenarios. Whether it's untangling dependencies between classes, simplifying complex conditional logic, or restructuring method compositions, participants will discover a rich toolkit of refactoring techniques at their disposal. Through the analysis of concrete, real-life cases, and hands-on exercises, learners will gain practical experience in applying these techniques to refactor Java applications effectively and efficiently.

 

The course covers the following main strategies for refactoring a Java application:

  • Smells within classes: Addressing issues related to method length, complexity, and cohesion within individual classes.
  • Smells between classes: Resolving dependencies, coupling, and code duplication across class boundaries.
  • Composing methods: Optimizing method structure and clarity for improved readability and maintainability.
  • Moving features between objects: Redistributing responsibilities and improving encapsulation through object-oriented design principles
  • Organizing data: Streamlining data structures and improving data access patterns for enhanced performance.
  • Simplifying conditional expressions: Clarifying conditional logic and reducing complexity for easier comprehension and maintenance.
  • Making method calls simpler: Refactoring method invocations to enhance code readability and modularity.
  • Dealing with generalization: Refactoring inheritance hierarchies and abstractions to promote code reuse and flexibility.
  • Refactoring with Java 8: Leveraging Java 8 features and functional programming paradigms for cleaner, more concise code.
  • Refactoring/testing: Integrating refactoring practices with automated testing to ensure code correctness and robustness.

 

By the end of this course, participants will:

  • Develop a keen eye for identifying code smells and diagnosing areas in need of refactoring within Java applications.
  • Acquire a comprehensive toolkit of refactoring techniques tailored to specific code scenarios, enabling them to address a wide range of code quality issues effectively.
  • Master the art of refactoring through hands-on practice and real-life case studies, gaining confidence in their ability to refactor Java code with precision and skill.
  • Cultivate a proactive mindset towards code maintenance and improvement, incorporating refactoring as an integral part of their software development workflow.
  • Harness the power of Java 8 features and functional programming concepts to refactor code more elegantly and efficiently.
  • Integrate refactoring practices seamlessly with automated testing to ensure code correctness and reliability in evolving codebases.

 

Join us on this transformative journey to become a master of code refactoring in Java. Whether you're a seasoned developer seeking to hone your skills or a newcomer eager to learn the ropes, this course offers invaluable insights and practical techniques that will empower you to elevate the quality of your code and become a more proficient Java craftsman.

After completing the course, a certificate is issued on the Luxoft Training form

Objectives

After the completion of the course, students will be able to:

  • Know refactoring principles
  • Explain the need for refactoring
  • Implement refactoring activities in development processes
  • Identify code smells
  • Make decisions on refactoring the problem code
  • Perform refactoring step-by-step
  • Use automated code refactoring tools

Target Audience

  • Developers
  • Technical Leads

Prerequisites

    • Know the basics of object-oriented programming
    • At least one year of work experience with object-oriented languages
    • Know UML

Roadmap

1. [Theory – 2h: Practice – 0.5h] Introduction

  • What is Refactoring
  • Rules and Strategies
  • Refactoring and Design
  • Building tests
  • Bad smells
  • Refactoring tools
  • Refactoring books

2. [Theory – 1.5h: Practice – 1h] Smells within classes

  • Measured smells
  • Names
  • Unnecessary complexity
  • Duplication
  • Conditional logic

3. [Theory – 0.5h: Practice – 1h] Smells between classes

  • Data
  • Inheritance
  • Responsibility
  • Accommodating Change
  • Library Classes

4. [Theory – 1h: Practice – 1h] Composing methods

  • Extract Method
  • Inline Method
  • Inline Temporary Variable
  • Replace Temporary Variable with Query
  • Introduce Explaining Variable
  • Split Temporary Variable
  • Remove Assignments to Parameters
  • Replace Method with Method Object
  • Substitute Algorithm 

5. [Theory – 1h: Practice – 1h] Moving features between objects

  • Move Method
  • Move Field
  • Extract Class
  • Inline Class
  • Hide Delegate
  • Remove the Middle Man
  • Introduce Foreign Method
  • Introduce Local Extension

6. [Theory – 2h: Practice – 2h] Organizing data

  • Encapsulate Field
  • Self Encapsulate Field
  • Encapsulate Collection
  • Replace Record with Data Class
  • Replace Data Value with Object
  • Replace Array with Object
  • Change Value to Reference
  • Change Reference to Value
  • Duplicate Observed Data
  • Change Unidirectional Association to Bidirectional
  • Change Bidirectional Association to Unidirectional
  • Replace the Magic Number with a Symbolic Constant
  • Replace Type Code with Class
  • Replace Type Code with Subclasses
  • Replace Type Code with State/Strategy
  • Replace Subclass with Fields

7. [Theory – 1h: Practice – 1h] Simplifying conditional expressions

  • Decompose Conditional
  • Consolidate Conditional Expression
  • Consolidate Duplicate Conditional Fragments
  • Remove Control Flag
  • Replace Nested Conditional with Guard Clauses
  • Replace Conditional with Polymorphism
  • Introduce Null Object
  • Introduce Assertion

8. [Theory – 1h: Practice – 1h] Making method calls simpler

  • Rename Method
  • Add Parameter
  • Remove Parameter
  • Separate Query from Modifier
  • Parameterize Method
  • Replace Parameter with Explicit Methods
  • Replace Parameter with Method
  • Introduce Parameter Object
  • Remove Setting Method
  • Hide Method
  • Replace Constructor with Factory Method
  • Encapsulate Downcast
  • Replace Error Code with Exception
  • Wrap Checked Exception into Unchecked
  • Replace Exception with Test

9. [Theory – 1h: Practice – 1h] Dealing with generalization

  • Pull Up Field
  • Pull Up Method
  • Pull Up Constructor Body
  • Push Down Method
  • Push Down Field
  • Extract Subclass
  • Extract Superclass
  • Extract Interface
  • Collapse Hierarchy
  • Form Template Method
  • Replace Inheritance with Delegation
  • Replace Delegation with Inheritance

10. [Theory – 0.5h: Practice – 1h] Refactoring with Java 8

  • Replace Anonymous Classes with Lambda Expressions
  • Use Method References
  • Use lambdas to implement the command pattern
  • Use lambdas to implement the strategy pattern
  • Process Collections Using Lambdas
  • Use streams for map/filter/reduce operations

11. [Theory – 1h: Practice – 1h] Refactoring and testing

  • Testing Fundamentals
  • Types of Software Testing
  • Test Driven Development
  • Refactoring with Tests
  • Java Testing Books

Total: theory 12,5h (52%), practice 11,5h (48%)



Related courses

You may also be interested in

Discover more about professional growth and skills development

contact us