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