I’ve just finished my second read-through of Test Driven Development by Kent Beck (thank you to Austin at Pivotal for loaning it to me!). Even on the second read, I must liken my experience of reading it to that of watching this lightsaber battle:
It’s fascinating and mesmerizing, and people who clearly know exactly what they are doing make lightspeed decisions back to back to back directly before my eyes. I watch and rewatch with a sense of awe, hoping that I, too, can one day make the split-second design decisions that Beck makes with such ease in both Java and Python. And, like anyone who has attempted to learn to reenact the above lightsaber battle, I found myself often pausing and rereading Beck’s examples in an effort to break them down and understand what, why, and how.
I imagine that the ultimate exercise for internalizing the lessons in TDD would be to, in fact, reenact Beck’s examples. If any of you fine readers would like to remotely (or even not remotely!) pair with me to reenact the Java example in Part 1 of this book, I will buy you some Starbucks. I will also record a video of our entire pairing experience and place it on youtube (and also this blog) for future generations of programmer Padawans to see.
In the meantime, I’d like to share some of the “what” questions I asked in those moments when I paused my reading of said Java example. So, we’ll go over some of the concepts of program design in Java that Beck discusses in the book, and I’ll show you the resources that proved most helpful to me in answering my questions.
So, without further ado, Design Concepts in Java as Discovered through Kent Beck’s TDD book:
INTERFACES (and why we prefer using interfaces to using classes where possible):
- This page of The Java Tutorials explains the concept of interfaces concisely and clearly: they’re used to dictate what many different objects and programs do, while leaving it up to the developers how those things get done—like a good manager. That said, I actually implemented my first interface not in Java…
- but in Go, with the help of this helpful manual that you can read cover to cover for free online. The relative syntactic simplicity of Go makes it a good language for focusing on concepts that one might later wish to translate into their programming in another language.
DEGENERATE CLASSES
- I had never heard of a degenerate class. Luckily, I found an extremely helpful thread on Stack Overflow (I rarely find Stack Overflow threads extremely helpful, so this is a milestone).
VALUE OBJECTS: I had also never heard of a value object, but I found it to be a relatively simple concept: an object in which the values of the instance variables of the object never change once they are set in the constructor—somewhat like constants. No need for additional resources on this one.
PUBLIC, PRIVATE, PROTECTED CLASS
- Twice in one day is absurd, but Stack Overflow has done it again.
- That said, for something like this, an example can prove extremely helpful. For that, Java Coffee Break offers a short one (that happens to involve money, just like the Java TDD example from the book!)
POLYMORPHISM: when an object has an is-a relationship with more than one class.
- Tutorials Point provides a clear explanation and an example. For me it was helpful to envision polymorphism as an inheritance lattice in contrast to an inheritance tree:
Gracias a Horicky for the image: http://horicky.blogspot.com/2012/04/basic-graph-analytics-using-igraph.html
ABSTRACT CLASSES
- The Java Tutorials come forward with a description of abstract classes—classes that exist only to be extended, and not to be instantiated—as well as an explanation of how they differ from interfaces. Hat tip.
I’m sure I’ll be coming back to this post to look at these resources again, so it made sense to share what I had collected :). And don’t forget about that open invitation to pair on a reenactment!