Chapter 3Design Approaches

In the middle of difficulties lies opportunity.

Albert Einstein

We can’t avoid manipulating state; that’s integral to programs we create. The compiler, for instance, takes a set of source files and creates bytecode, and the Mail app keeps track of unread emails, among other things.

As we gain experience with Java, we’re often set in the way we design programs. Objects encapsulate state, and their methods help transition between selected valid states. I scoffed when someone said we can create significant code that doesn’t change state. Later when he showed me how, I was intrigued and enlightened, like that kid in the bookstore.[8]

Manipulating state doesn’t necessarily mean mutating state. Think of state transformation ...

Get Programming Concurrency on the JVM now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.