Clean Code Fundamentals
$19.99
Minimum price
$24.99
Suggested price

Clean Code Fundamentals

Hands-on Guide to Understand the Fundamentals of Software Craftsmanship and Clean Code in Java

About the Book

Nothing affects the work of a team as much as bad, illegible, sloppy, and quickly written code that has not been designed carefully. Team dynamics can be improved, requirements can be redefined, and the schedule can be modified. However, if bad code takes over, it becomes more and more a burden for the team.

Programmers should develop all the time. Even if they think that they have sufficient skills and knowledge to move around in current projects, they should not stop there, and it is worthwhile for them to learn new concepts, approaches, language, and frameworks from time to time. Learning should be a journey and not a destination.

This book discusses the basics of software qualityprinciplespatterns, and best practices of writing better code. It also contains many code examples in Java of increasing complexity. Among other things topics like software metrics, static software testing, and tools which can help to measure software quality will be covered.

This is a Forever Edition. That means that the book will see periodic updates, which are free for you. The book will use the latest Java version for the examples provided. New content and improvements will be released every 2-3 weeks.

About the Author

Martin Hock
Martin Hock

Martin is a principal software engineer with over 25 years of experience in application design and development. His primary focus is on lightweight Java and open source technologies with expertise in software architecture, web technologies, and the Spring ecosystem.


He has found that teaching is the best way to learn software development. He is a part-time lecturer at two universities and teaches courses on Java, Software Craftsmanship and Clean Code.

Bundles that include this book

$44.98
Bought separately
$29.99
Minimum price
$34.99
Suggested price

Table of Contents

  • Preface
    • What is the goal of this book?
    • Which topics can you expect?
    • Who should read this book?
    • What you must learn about Software Development yourself?
    • What about the code examples and typographic conventions?
    • Which literature is this book based on?
    • Giving Feedback?
  • 1 Introduction to Software Craftsmanship and Clean Code
    • 1.1 A Passion for Software Development
    • 1.2 Manifesto for Software Craftsmanship
    • 1.3 Clean Code Developer
    • 1.4 Boy Scout Rule
    • 1.5 Broken Windows Theory
    • 1.6 Cargo Cult Programming
    • 1.7 Knowledge - Expertise
  • 2 Basics of Software Design
    • 2.1 Software Design Pyramid
    • 2.2 Basic concepts of OOD
    • 2.3 Goals of Software Design
    • 2.4 Symptoms of bad design
    • 2.5 Criteria for good design
    • 2.6 Information Hiding
    • 2.7 Cohesion
    • 2.8 Coupling
    • 2.9 Cohesion - Coupling
    • 2.10 Big Ball of Mud
    • 2.11 Architecture Principles
    • 2.12 Cognitive Psychology and Architectural Principles
    • 2.13 Layered Architecture
      • 2.13.1 Use of Layered Architecture
      • 2.13.2 Violated Layered Architecture
      • 2.13.3 Horizontal Layering
      • 2.13.4 Feature-Based Layering - Single package
      • 2.13.5 Feature-Based Layering - Slices before layers
      • 2.13.6 Feature-Based Layering – Hexagonal Architecture
      • 2.13.7 The Java Module System
    • 2.14 Architecture Documentation
    • 2.15 Testing the Architecture and Design
    • 2.16 Software Engineering Values
    • 2.17 Team Charter
  • 3 Clean Code Best Practices
    • 3.1 Communicate through code
      • 3.1.1 Use Java code conventions and avoid misinformation
      • 3.1.2 Choose an expressive name and avoid mental mapping
      • 3.1.3 Make differences clear with meaningful variable names
      • 3.1.4 Use pronounceable names
      • 3.1.5 Do not hurt the readers
      • 3.1.6 Don`t add redundant context
      • 3.1.7 Don’t add words without additional meaning
      • 3.1.8 Don’t use and or or in method names
      • 3.1.9 Use positive names for boolean variables and functions
      • 3.1.10 Respect the order within classes
      • 3.1.11 Group by line break
      • 3.1.12 Prefer self-explanatory code instead of comments
      • 3.1.13 Refactor step by step
    • 3.2 Bad comments
      • 3.2.1 Redundant comments
      • 3.2.2 Misleading comments
      • 3.2.3 Mandatory comments
      • 3.2.4 Diary comments
      • 3.2.5 Gossip
      • 3.2.6 Position identifier
      • 3.2.7 Write-ups and incidental remarks
      • 3.2.8 Don’t leave commented out code in your codebase
      • 3.2.9 Rules for commenting
    • 3.3 Classes and objects
      • 3.3.1 Classes
      • 3.3.2 Functions
      • 3.3.3 Variables
    • 3.4 Shapes of code
      • 3.4.1 Spikes
      • 3.4.2 Paragraphs
      • 3.4.3 Paragraphs with headers
      • 3.4.4 Suspicious comments
      • 3.4.5 Intensive use of an object
  • 4 Software Quality Assurance
    • 4.1 Test Pyramid
    • 4.2 Test Classification
    • 4.3 Test-driven Development (TDD)
    • 4.4 Unit testing with JUnit 5
      • 4.4.1 Unit Tests
      • 4.4.2 JUnit 5
      • 4.4.3 First unit test
      • 4.4.4 Assertions
        • 4.4.4.1 assertEquals() / assertArrayEquals()
        • 4.4.4.2 assertSame() / assertNotSame()
        • 4.4.4.3 assertTrue() / assertFalse() / assertAll()
        • 4.4.4.4 assertNull() / assertNotNull()
        • 4.4.4.5 assertThrows()
        • 4.4.4.6 assertTimeout()
        • 4.4.4.7 fail()
      • 4.4.5 Annotations
        • 4.4.5.1 @Test
        • 4.4.5.2 @BeforeEach / @AfterEach
        • 4.4.5.3 @BeforeAll / @AfterAll
        • 4.4.5.4 @Disabled
        • 4.4.5.5 @DisplayName
        • 4.4.5.6 @Tag
        • 4.4.5.7 @Timeout
      • 4.4.6 Assumptions
        • 4.4.6.1 assumeFalse()
        • 4.4.6.2 assumeTrue()
        • 4.4.6.3 assumingThat()
      • 4.4.7 Parameterized Tests
        • 4.4.7.1 @ValueSource
        • 4.4.7.2 @MethodSource
        • 4.4.7.3 @CsvSource
        • 4.4.7.4 @CsvFileSource
        • 4.4.7.5 @ArgumentsSource
    • 4.5 More on Unit Tests
      • 4.5.1 Heuristics
      • 4.5.2 Naming of test methods
      • 4.5.3 Object Mother
      • 4.5.4 Test Data Builder
      • 4.5.5 F.I.R.S.T
    • 4.6 Mocking with Mockito
      • 4.6.1 Types of Test Double
      • 4.6.2 Activation
      • 4.6.3 Annotations
        • 4.6.3.1 @Mock
        • 4.6.3.2 @Spy
        • 4.6.3.3 @Captor
    • 4.7 Code Coverage
    • 4.8 Static Code Analysis
    • 4.9 Continuous Integration
      • 4.9.1 Differences between CI, CD, and CD
      • 4.9.2 CI Workflow
      • 4.9.3 Preconditions
      • 4.9.4 Advantages and Disadvantages
      • 4.9.5 Best Practices
  • 5 Design Principles
    • 5.1 Goal of Design Principles
    • 5.2 Overview of Design Principles
    • 5.3 SOLID Principles
      • 5.3.1 Single Responsibility Principle
        • 5.3.1.1 Example: Modem
        • 5.3.1.2 Example: Book
        • 5.3.1.3 Example: Product
      • 5.3.2 Open Closed Principle
        • 5.3.2.1 Example: LoanRequestHandler
        • 5.3.2.2 Example: Shape
        • 5.3.2.3 Example: HumanResourceDepartment
        • 5.3.2.4 Example: Calculator
        • 5.3.2.5 Example: FileParser
      • 5.3.3 Liskov Substitution Principle
        • 5.3.3.1 Example: Rectangle
        • 5.3.3.2 Example: Coupon
        • 5.3.3.3 Example: Bird
      • 5.3.4 Interface Segregation Principle
        • 5.3.4.1 Example: MultiFunctionDevice
        • 5.3.4.2 Example: TechEmployee
        • 5.3.4.3 Example: StockOrder
      • 5.3.5 Dependency Inversion Principle
        • 5.3.5.1 Example: UserService
        • 5.3.5.2 Example: Logger
    • 5.4 Packaging Principles - Cohesion
      • 5.4.1 Release Reuse Equivalency Principle
      • 5.4.2 Common Closure Principle
      • 5.4.3 Common Reuse Principle
    • 5.5 Packaging Principles - Coupling
      • 5.5.1 Acyclic Dependencies Principle
        • 5.5.1.1 Example: Cyclic dependency
      • 5.5.2 Stable Dependencies Principle
      • 5.5.3 Stable Abstractions Principles
    • 5.6 Further Design Principles
      • 5.6.1 Speaking Code Principle
      • 5.6.2 Keep It Simple (and) Stupid!
      • 5.6.3 Don’t Repeat Yourself / Once and Only Once
      • 5.6.4 You Ain’t Gonna Need It!
      • 5.6.5 Separation Of Concerns
  • 6 Design Patterns of the Gang of Four
    • 6.1 Creational
      • 6.1.1 Singleton
        • 6.1.1.1 Example: Lazy loading
        • 6.1.1.2 Example: Eager loading
        • 6.1.1.3 Example: Enum singleton
      • 6.1.2 Builder
        • 6.1.2.1 Example: MealBuilder
        • 6.1.2.2 Example: PizzaBuilder
        • 6.1.2.3 Example: Email
        • 6.1.2.4 Example: ImmutablePerson
      • 6.1.3 Factory Method
        • 6.1.3.1 Example: Logger
        • 6.1.3.2 Example: Department
      • 6.1.4 Abstract Factory
        • 6.1.4.1 Example: Car
      • 6.1.5 Prototype
        • 6.1.5.1 Example: Person - Shallow copy
        • 6.1.5.2 Example: Person - Deep copy
        • 6.1.5.3 Example: Person - Copy constructor / factory
    • 6.2 Structural
      • 6.2.1 Facade
        • 6.2.1.1 Example: Travel
        • 6.2.1.2 Example: SmartHome
      • 6.2.2 Decorator
        • 6.2.2.1 Example: Message
        • 6.2.2.2 Example: Window
      • 6.2.3 Adapter
        • 6.2.3.1 Example: Sorter
        • 6.2.3.2 Example: TextFormatter
      • 6.2.4 Composite
        • 6.2.4.1 Example: Graphic
        • 6.2.4.2 Example: Organization Chart
      • 6.2.5 Bridge
        • 6.2.5.1 Example: Message
        • 6.2.5.2 Example: Television
      • 6.2.6 Flyweight
        • 6.2.6.1 Example: Font
        • 6.2.6.2 Example: City
      • 6.2.7 Proxy
        • 6.2.7.1 Example: Spaceship
        • 6.2.7.2 Example: ImageViewer
    • 6.3 Behavioural
      • 6.3.1 State
        • 6.3.1.1 Example: MP3Player
        • 6.3.1.2 Example: Door
      • 6.3.2 Template Method
        • 6.3.2.1 Example: Compiler
        • 6.3.2.2 Example: Callbackable
      • 6.3.3 Strategy
        • 6.3.3.1 Example: Compression
        • 6.3.3.2 Example: LogFormatter
      • 6.3.4 Observer
        • 6.3.4.1 Example: DataStore
        • 6.3.4.2 Example: Influencer
      • 6.3.5 Chain of Responsibility
        • 6.3.5.1 Example: Purchase
        • 6.3.5.2 Example: Authentication
      • 6.3.6 Command
        • 6.3.6.1 Example: FileSystem
        • 6.3.6.2 Example: Television
      • 6.3.7 Interpreter
        • 6.3.7.1 Example: HexBinary
        • 6.3.7.2 Example: Calculator
      • 6.3.8 Iterator
        • 6.3.8.1 Example: Cars - intern
        • 6.3.8.2 Example: Cars - extern
      • 6.3.9 Mediator
        • 6.3.9.1 Example: Chat
        • 6.3.9.2 Example: Aircraft
      • 6.3.10 Memento
        • 6.3.10.1 Example: Editor
        • 6.3.10.2 Example: Balance
      • 6.3.11 Visitor
        • 6.3.11.1 Example: Fridge
        • 6.3.11.2 Example: Figures
  • Notes

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

Now, this is technically risky for us, since you'll have the book or course files either way. But we're so confident in our products and services, and in our authors and readers, that we're happy to offer a full money back guarantee for everything we sell.

You can only find out how good something is by trying it, and because of our 100% money back guarantee there's literally no risk to do so!

So, there's no reason not to click the Add to Cart button, is there?

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earnedover $13 millionwriting, publishing and selling on Leanpub.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub