Refactoring in Java: Improving code design and maintainability for Java developers 1st Edition Anonymous download pdf
Refactoring in Java: Improving code design and maintainability for Java developers 1st Edition Anonymous download pdf
com
https://ebookmeta.com/product/refactoring-in-java-improving-
code-design-and-maintainability-for-java-developers-1st-
edition-anonymous/
OR CLICK HERE
DOWLOAD NOW
https://ebookmeta.com/product/refactoring-improving-the-design-of-
existing-code-2nd-edition-martin-fowler/
ebookmeta.com
https://ebookmeta.com/product/java-to-kotlin-a-refactoring-
guidebook-1st-edition-duncan-mcgregor/
ebookmeta.com
https://ebookmeta.com/product/survivors-2-a-lost-world-harem-1st-
edition-jack-porter/
ebookmeta.com
https://ebookmeta.com/product/fight-to-win-inside-poor-people-s-
organizing-1st-edition-a-j-withers/
ebookmeta.com
https://ebookmeta.com/product/routine-outcome-monitoring-in-couple-
and-family-therapy-the-empirically-informed-therapist-tilden-terje/
ebookmeta.com
https://ebookmeta.com/product/python-for-scientists-3rd-edition-john-
m-stewart/
ebookmeta.com
https://ebookmeta.com/product/combat-core-1st-edition-jim-smith/
ebookmeta.com
Principles of Pathophysiology 2nd Edition Shane Bullock
https://ebookmeta.com/product/principles-of-pathophysiology-2nd-
edition-shane-bullock/
ebookmeta.com
Refactoring in Java
Copyright © 2023 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or
transmitted in any form or by any means, without the prior written permission of the publisher,
except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information
presented. However, the information contained in this book is sold without warranty, either express
or implied. Neither the author, nor Packt Publishing or its dealers and distributors, will be held liable
for any damages caused or alleged to have been caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and
products mentioned in this book by the appropriate use of capitals. However, Packt Publishing
cannot guarantee the accuracy of this information.
Production reference:1081223
Grosvenor House
11 St Paul’s Square
Birmingham
B3 1RB, UK.
ISBN 978-1-80512-663-8
www.packtpub.com
I dedicate this book to Cristina, the love of my life, and my children, Alessandro and Andrea.
I believe, in life, the most important thing is to keep learning and getting better.
Thanks for showing me something new every day.
– Stefano
Contributors
Siddhesh Nikude is a software craftsperson who believes in improving the world’s software
development by writing better software and teaching others how to do it. He carries over 10+ years
of experience and prefers calling himself a generalist.
Siddhesh started his career as a smart card developer, where he was introduced to Clean Code and
XP. It was then he started working in an iterative and incremental approach to notice effective
results. Not only does it improve the design and safety of the software, but it also improves the lives
of the people working on it. He has worked in a variety of roles from developer to transformation
coach on a variety of projects. He has mentored teams in B/TDD, mutation and micro testing, CI/CD
pipelines, XP/Lean practices, Clean Code and SOLID principles, DORA metrics, Monte-Carlo
simulation, Scrum, Delivery Automation, Test Pyramid, User Stories/Slicing, and Chartering. As a
developer, he has worked with Java, Kotlin, Go, TypeScript, React-Native, and so on.
Table of Contents
Preface
What is Refactoring?
What do we mean by refactoring?
Refactoring and clean code
Misconceptions about refactoring
Why you should consider refactoring
Improving the design of your software
Maintainability and scalability
Understanding, avoiding, and fixing bugs
Faster development
When you should refactor
The “Rule of Three”
Preparatory refactoring for smooth feature implementation
Refactoring for bug fixing
Comprehension refactoring
The “Boy Scout Rule”
Planned refactoring
Long-term refactoring and “Branch by Abstraction”
Refactoring in a code review
What you should refactor
Impact analysis
Risk assessment
Value estimation
Prioritization matrix
Further considerations
Refactor or rewrite?
Summary
Further reading
Code Smells
Duplicated code
Long methods
Replace temporary variables with query methods
Parameter object
Replace a function or method with a command
Decompose conditionals
Split loops
Large classes
Switches
Primitive Obsession
Middle man
Message chains
Feature envy methods
Divergent change
Shotgun Surgery
God object
Summary
Further reading
Testing
Why you should test (often)
Identifying and fixing defects
Ensuring quality and reliability
Customer satisfaction
Compliance and standards
Security
Integration and compatibility
Confidence and peace of mind
Unit testing
JUnit framework
Integration testing
Mockito
Contract testing
Be safe – checking and improving your test coverage
What is test coverage?
A Java code coverage tool – JaCoCo
Test-driven development
Advantages of TDD
Summary
Further reading
Refactoring Techniques
Writing better methods
Extract Method
Inline Method
Extract and inline variables
Combining a function into a class
Moving features between objects
Moving a method or field
Moving statements into/from methods
Hiding delegates
Removing dead code
Organizing data
Field encapsulation
Replacing primitives with objects
Replacing type code with subclasses
Simplifying conditional logic
Returning a special case instead of null
Using polymorphism instead of conditions
Removing duplicated conditions
Guard clauses
Simplifying method calls
Avoiding side effects
Removing setter methods
Using generalization
Pull up field
Push down field
Pull up method
Push down method
Template method
Using enums instead of constants
Summary
Further reading
Metaprogramming
What is metaprogramming?
Exploring compile-time metaprogramming tools
Lombok
MapStruct
Exploring runtime metaprogramming tools
Reflection
Weighing the pros and cons of metaprogramming
Summary
Further reading
Index