Preface
Optimise for Clarity
What is an object, anyway?
- What’s all this got to do with Java?
- A simple example: Greeting users
- The big idea: calling code is simple
- Object Oriented Design is Behaviour Driven Design
Clean Code
- Good Names
- Design methods around behaviours, not data
- Hidden data - No getters, no setters
Aggregates: More than one
- Greeting more than one user
- Using forEach - not a loop
- Aggregate methods work on all the things
Collaboration
- Basic Mechanics
- Example: Simple Point of Sale
Test Driven Development
- Outside-in design with TDD
- First test: total starts at zero
- Arrange, Act, Assert - a rhythm inside each test
- Red, Green, Refactor - a rhythm in between tests
- Second test: Adding an item gives us the right total
- Designing the second feature
- TDD Steps - Too much? Too little?
- YAGNI - You Ain’t Gonna Need It
- YAYA - Yes, You Are
- Optimise for Clarity with well-named tests
- TDD and OOP - A natural fit
- FIRST Tests are usable tests
- Real-world TDD
Polymorphism - The Jewel in the OOP Crown
- Classic example: Shape.draw()
- The Shape Interface
- Tell Don’t Ask - the key to OOP
The SOLID Principles
- The five SOLID principles
- SRP Single Responsibility - do one thing well
- DIP Dependency Inversion: Bring out the Big Picture
- LSP Liskov Substitution Principle - Making things swappable
- OCP Open/Closed Principle - adding without change
- ISP Interface Segregation Principle - honest interfaces
TDD and Test Doubles
- Test Doubles - Stubs and Mocks
- DIP for Unit Tests - Stubs and Mocks
- Mocking libraries
- Self-Shunt mocks and stubs
Refactoring
- What is refactoring?
- Rename Method, Rename Variable
- Extract Method
- Change Method Signature
- Extract Parameter Object
- Can we refactor anything into anything else?
Hexagonal Architecture
- The problems of external systems
- The Test Pyramid
- Removing external systems
- The Hexagonal Model
- Inversion / Injection: Two sides of the same coin
Handling Errors
- Three kinds of errors
- The null reference
- Null object pattern
- Zombie object
- Exceptions - a quick primer
- Design By Contract, Bertrand Meyer style
- Fatal errors: Stop the world!
- Combined approach: Fixable and non-fixable errors
- Which approach is best?
- NullPointerException
- Application Specific Exceptions
- Error object
- Optionals - Java 8 streams approach
- Review: Which approach to use?
Design Patterns
- Mechanism and Domain
- Patterns: Not libraries, not frameworks
- Strategy
- Observer
- Adapter
- Command
- Composite
- Facade
- Builder
- Repository
- Query
- CollectingParameter
- Item-Item Description
- Moment-Interval
- Clock
- Rules (or Policy)
- Aggregate
- Cache
- Decorator
- External System (Proxy)
- Configuration
- Order-OrderLineItem
- Request-Service-Response
- Anti-Patterns
OOP Mistakes - OOP oops!
- Broken Encapsulation - Getters Galore!
- Broken Inheritance
- Bird extends Animal
- Square extends Rectangle
- Inheriting implementation
- Broken Shared State
- Ordinary Bad Code
Data Structures and Pure Functions
- System Boundaries
- Fixed Data, Changing Functions
- Algorithms and Data Structures
Putting It All Together
- No step-by-step plans
- Getting Started
- Perfection and Pragmatism
- Getting Past Stuck
Further Reading
- Agile Software Development, Robert C Martin
- Growing Object Oriented Software Guided By Tests, Freeman and Pryce
- Refactoring, Martin Fowler
- Design Patterns Helm, Johnson, Richards, Vlissides
- Domain Driven Design, Eric Evans
- Applying UML with Patterns, Craig Larman
- Home page for this book
- My Blog
- My Quora Space
- LeanPub page
Cheat Sheet
- Behaviours First
- Design Principles
- Clean Code
- General Code Review Points
About the Author
- Thanks