Michael Urban is a biology student and computer programmer for the Lion
Research Center at the University of Minnesota where he develops
applications using Java, Python, and C that assist in research involving
African lions in Tanzania, East Africa. Michael Urban is also an editor at Javalobby and a technical writer who
has written and done technical editing for Pearson Education.
I will be honest. When I first saw this book, I judged it by its cover. I also judged it by thumbing through it and looking at the gaudy captions and pictures in it. Based on that, combined with its use of teen slang such as "wicked-cool", I was ready to write this book off as being geared towards high school age nerds rather than serious software engineers. But I could not have been more wrong...
I have to say this is one of the best books on Java programming I have ever read, and that I am a much better programmer now than I was before I read it. Most Java books focus on Java syntax, and on Java's support for object oriented programming. However, they fall very short when it comes to actually teaching how to apply object oriented programming. Many computer science courses also fall short when it comes to teaching how to actually apply object oriented programming, hence we end up with programmers who over-use inheritance and thus write code that is very difficult to maintain. That is where Head First Design Patterns come to the rescue.
The book starts off by explaining its very unorthodox teaching style, and how your brain is more likely to remember something that is presented in a unique way. Things that trigger some kind of emotion are far more likely to be remembered than things that are presented in a typical dry academic style. After reading the book, I would say the teaching style works very well. I remembered far more from this book than I do from most other programming books. Even though the emotion triggered was often a sense of groaning because of a bad pun, or the use of some over-used slang, even these emotions did cause me to remember the material in question.
After explaining the unorthodox teaching style, the book moves on to a simple and rather humorous example of where over-use of inheritance ended up causing unforeseen consequences as a project evolved, thus creating a maintenance nightmare. The book then considers various ways to solve the problem. Unlike many books that only present one solution which is considered by the author to be the best, this one gets you to think about many possible solutions, including some that are very bad ones. After getting you to think about them, the book discusses why the solutions are a bad idea. For example, in the first chapter (which is available with this review as a sample chapter), the book discusses the possibility of using an interface to get rid of the unforeseen consequences that the inheritance caused. However, it then goes on to discuss how the interface creates an even bigger maintenance nightmare since although it solves the first problem, code re-use has now gone out the window.
Had I been working in C++, my first inclination would have been to solve the problem in chapter one by using multiple inheritance, but this only demonstrates that like many other programmers, I tend to over-use inheritance. The book closes the chapter by presenting a solution that involves adapter classes.
The book continuously stresses the idea of favoring composition over inheritance in most cases, as well as the idea of programming to an interface rather than an implementation. However, rather than use dry technical explanations for this, the book uses "Has a" is often better than "Is a" examples. For example, not all bathrooms have bathtubs, so we probably don't want to include a bathtub in a Bathroom class. However, neither would we want to use multiple inheritance even if we could, since a bathroom IS NOT A bathtub, but rather, a bathroom HAS A bathtub.
The book then moves on to cover other design patterns, presenting them in the same style of defining a basic (often humorous) problem and discussing various ways to solve it. Rather then give try technical explanations of Observers for example, the book presents real-life interactions between people that involve observers to demonstrate how they can be used.
The book also teaches in a very conversational style. For example, most of the book is written as if you were discussing the problem and its various solutions with another programmer. This tends to create a dynamic style of learning with a dynamic interaction between the reader and the book. This is really a breath of fresh air compared to the typical programming book which uses a static "spoon feed" method of teaching where you are only a consumer rather than a producer.
I can say this is one of the best books on Java I have ever read. I was able to maintain more information than from most other programming books, and I also learned a lot more because of the books dynamic style of teaching rather than a simple spoon feeding of static information like most programming books do. If I were to use an academic analogy, Head First Design Patterns is like doing directed research, where as most other books are like sitting in a lecture. Most people learn better from directed research because they are actively working on solving a problem and carrying out discussions with colleagues and teachers regarding ideas and why they might or might not work, where as with lectures, you are pretty much passively being fed information. This is an activity our brains are rather averse to, and which causes us to fall asleep, or space out information such that we miss entire sections of lecture, or have to go back and re-read something because we find that although we were reading we were day dreaming at the same time. Thus, we have no idea what we just read. Head First Design Patterns solves this problem by keeping the reader actively involved and by constantly asking discussion based questions.
If you learn well using a "directed research" and active learning approach, I would highly recommend this book. I have learned more about object oriented design from this book than from any other book I have ever read on object oriented programming. And not only did I learn more, but I retained far more of what I learned. I am a much better programmer now than I was before I read this book. And there are very few books I can say that about.
Check out "Head First Design Patterns" on O'Reilly's website.
Download Chapter 3: The Decorator Patterns!
Purchase "Head First Design Patterns" on Amazon and help Javalobby.