Java OOP Done Right
$24.95
Minimum price
$24.95
Suggested price

Java OOP Done Right

Create object oriented code you can be proud of with modern Java

About the Book

Object Oriented Programming in Java - Done Right!

You've seen awful Java code and you're sick of it. Wasn't OOP supposed to make programming easier? Why is this code so bad?

Because it was done wrong, that's why. It wasn't even OOP code. It was a tangled mess of getters and setters, giant untestable methods and organised so badly, you'd think the keyboard just fell down some stairs.

We're going to learn how to do it right. You will learn:

  • Designing objects with behaviours and secrets
  • What encapsulation really means
  • Simplifying conditional code with polymorphism
  • Using Test Driven Development to find behaviours
  • SOLID principles - understand them, use them
  • Design Patterns you will actually use
  • Refactoring - improving your code as you learn more
  • Hexagonal Architecture - decoupling external systems to improve test
  • Handling errors with style
  • OOP Mistakes - how to avoid them

With your next project, you're going to code Java OOP like a champ.

Craft code you can be proud of!

  • Share this book

  • Categories

    • Java
    • Software Engineering
    • Software Architecture
  • Feedback

    You must own a copy of this Book to access the forums.

    Email the Author(s)

About the Author

Alan Mellor
Alan Mellor

Starting from age 12, Alan Mellor has four decades of experience developing software in various companies, startups and as a freelancer.

From a humble Sinclair ZX81 home computer with 1k of RAM, Alan has progressed to creating systems for industrial, defence, e-commerce, games and mobile phones.

Some you may have heard of: Nokia Bounce, The Ericsson R380s smartphone, The Red Arrows flight simulator from 1985 and Fun School 2. All had Alan's code in them. Other code sits there quietly, doing its thing unnoticed. Yet more has been consigned to the great /dev/null of history.

More recently, Alan has been involved with training UK Level 4 Apprentices. He has designed and delivered content that hopefully helps 'switch the light on' about programming.

Alan also enjoys dabbling variously with guitars, electronics, videography and cheeseboards. You just can't beat a great Roquefort with Rioja.

Table of Contents

  • 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
    • LinkedIn
    • LeanPub page
  • Cheat Sheet
    • Behaviours First
    • Design Principles
    • Clean Code
    • General Code Review Points
  • About the Author
    • Thanks
  • 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...

80% Royalties. Earn $16 on a $20 book.

We pay 80% royalties. That's not a typo: you earn $16 on a $20 sale. If we sell 5000 non-refunded copies of your book or course 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