Slashdot Mirror


Pattern Hatching: Design Patterns Applied

Tal Cohen, one of our best book reviewers thought that the Slashdot audience would appreciate Pattern Hatching: Design Patterns Applied, a book written by John Vlissides. This book is not one of the many new pattern catalogs, this book shows how patterns are applied in real life -- and also includes some interesting guidelines for would-be pattern writers. Pattern Hatching: Design Patterns Applied author John Vlissides pages 172 publisher Addison-Wesley, 06/1998 rating 7/10 reviewer Tal Cohen ISBN 0-201-43293-5 summary Not one of the many new pattern catalogs, this book shows how patterns are applied in real life -- and also includes some interesting guidelines for would-be patternwriters. Along with all the hoopla surrounding patterns these days comes more than a little confusion, consternation, and misinformation. This is partly a reflection of how new the field is to mainstream software developers even though it's not, strictly speaking, a new field. It's a fast-moving field too, creating vacuums of facts. And yes, we pattern proponents deserve some of the blame for not educating people as thoroughly as we'd like, though not for lack of trying.

John Vlissides, a member of the "Gang of Four" -- the authors of Design Patterns, presents another book on the subject. In part, this book presents some important aspects in using patterns; hence the subtitle "Design Patterns Applied" is right on the spot. Vlissides shows when certain patterns are used in real life, and even quotes a lot of e-mail from other users, showing patten advantages and, notably, weaknesses. As Vlissides states, "This book conveys something very important that's missing in the more academic and published Design Patterns book -- that patterns are the result of real, working programmers who don't get everything right the first time, and who struggle with the pragmatics of recurring design practices" (page x). Herein lies the book's greatest strength. Another part is aimed for pattern writers, rather than users. Sadly, these is no clear separation between these two aspects of the book.

The book is basically a collection of Vlissides's columns in C++ Report, and this is arguably the book's weakest point: if you're not intimately familiar with the little details of C++, you'll miss much of the action. This is sad, because the original Design Patterns book was careful to present patterns in a relatively language-independent manner, both in C++ and in Smalltalk. Here, the view is strongly biased towards C++, in ways that sometimes would annoy (or amuse) users of other languages, such as Smalltalk or Java.

Consider, for exmaple, Chapter 3: "Themes and Variations". A large portion of the chapter deals with the de-allocation problem of Singleton objects. Any programmer who uses a garbage-collecting language will be simply amused by the entire hoopla. The only conclusion from the entire discussion, one that the author himself admits (p. 69 and elsewhere), is that the lack of garbage collection greatly increases design complexity, in addition to program complexity. A design that had the potential of being elegant turns out into an ugly monster by the need to manually manage memory deallocation. Not to mention the suggested use of "delete this" (p. 41). The author is "not sure why, but [...] people wince at delete this". Hint, John: objects sometimes reside on the stack. In which case delete this can have very... interesting consequences. (True, in the context of a Singleton, where allocation is controlled and cannot occur on stack, this specific problem is not present, and yet "delete this" is such an evil construct, with such horrible possible results, that I'd rather avoid it even in such controlled cases.)

And sadly, the entire discussion on the use of Singletons ignores what I've come to conlude is the pattern's worst, and most common, misuse: Singletons, in my experience, are a tempting (and in practically all cases wrong) replacement for global variables. A designer that finds a need for a global variable simply replaces it with a Singleton, and pronounces that not only he's not using globals, but rather he's using a known pattern, which must mean his design is good.

Chapter 2 is a tour-de-force of using "classical" patterns, those presented in the original Design Patterns book. The examples look a little forced, and life too simple (every problem has a corresponding pattern that fits it like a glove), and yet it is a most educating read. For one relatively simple problem, the author comes up with an elegant solution that uses no less than six patterns (Proxy, Composite, Template Method, Visitor, Mediator and Singleton) -- and suggests an enhancement using a seventh one (Observer). This discussion alone could be worth the effort of reading the book, as it examplifies the correct and practical use of patterns in real life. The end of the chapter presents a very nice kind of diagram, invented by Erich Gamma, which could be very useful indeed. This "pattern:role annotation", as Gamma calls it, allows people who are sufficiently fluent in the pattern language of design to immediately grasp the role of different objects, even in a large design.

Chapters 4 and 5 are aimed mainly for pattern developers, though this is not clear when one begins to read them. It includes an example of the Gang of Four's elaborate discussions about pattern design, with lots of quotes from e-mail messages, etc. This is interesting only to a certain extent. The discussion, basically, is about whether Multicast should be presented as a pattern in its own right, or as an adaptation of the Observer pattern. Most of the discussion seemed to be dealing with minute neuances, but the conclusion (the presentation of a whole new pattern, "Typed Message"), is a beautiful one.

The concluding chapter (5) is titled "Seven Habits of Effective Pattern Writers". The name says it all. Though some of the advice presented (e.g. number 5, "Presenting Effectively") are trivial, others (e.g. number 1, "Taking Time to Reflect") are very educating. (Don't be mislead by that simple title, "Taking Time to Reflect". Vlissides provides some real important tips under this seemingly obvious one.)

In conclusion, if you do a lot of object-oriented design, and use (or consider using) design patterns, reading this book can be a good use of your time; but unless you spend time on designing patterns, too, you might wish to simply skim the last two chapters.

Pick this book up at ThinkGeek.

For additional book reviews, please visit http://www.forum2.org/tal/books.

20 of 95 comments (clear)

  1. Superb by MosesJones · · Score: 2

    Excellent review, which almost forced me to buy the book. The finest thing about the patterns books are that we can all finally put the same names to practices we've used for years.

    --
    An Eye for an Eye will make the whole world blind - Gandhi
  2. Need help ? by maroberts · · Score: 3

    If you didn't understand a word of this review [and I've got to admit I came close] then perhaps this web site will help

    Design Patterns

    This is the homepage of the previous book in the series.

    --

    Donte Alistair Anderson Roberts - hi son!
    Karma: Chameleon

  3. Patterns are beautiful! by Dacta · · Score: 5

    I love patterns. I suspect that many /. readers are going to say "patterns - and all that OO stuff is just another software development technique that will die in five years".

    It's not - and those of you who code large systems that are underfunded, and have too short deadlines know this.

    Patterns - and to a certian extent - OO design, allow software development to become engineering, with all the advantages that brings.

    In particular, reuse of subsystems has made (non-software) engineering a profession that produces reliable products most of the time.

    If you compare that to software engineering, we are still in the early years of last century. Before standadised engineering components (girders, bolts, whatever) everyone had to make them for themselves. Now, you can just go and buy them and know how reliable they are.

    Patterns allow us to develop systems in repeatable ways that are known (proven) to work. Combined with component reuse, I'm convinced they are the only way that we are going to be able to keep up with the increase in complexity of the systems we build.

    The other advantage is that Patterns give us a shared vocabulary. Yesterday, I was discussing with another programmer how we could allow various parts of the system we are building to get notification of user logons and log offs.

    He starts trying to explain this complex system of events, and callback registration, and I go - "The Observer Pattern?", he goes "Yep" and we both know exactly what we are doing. You can't beat that.

    I don't know about this book - I'm not a big C++ fan anyway, but if you haven't read about patterns get yourself the Gang of Four's book and do yourself a favour.

    1. Re:Patterns are beautiful! by infodragon · · Score: 2

      I agree patterns are beautiful! I've developed in C++ for 6 years. The most influential book in my development career is design patterns.

      Right now I am working on an underfunded project. We are developing a realtime system to monitor many (150+) seperate subsystems. In general only 1 update a second from each subsystem is good enough but there are times where we will need updates from a couple of susbystesm 1000 times a second for a couple of seconds. The subsystems can communicate across a couple of different communication lines. Each of these lines uses different communication protocals. Right now we are useing RS-485 and CAN BUS 2.01b. The development of this is unimaginable. The patterns that I have found most usefull are the singleton and the factory. So much detail is abstracted using the factory I can add new subsystes/communications to the system by only affecting 5% of the code. Another pattern that I am using (I think it is actor, it's been a while since I read the book and it isn't handy right now) has abstracted the details of communicating with different subsystems so much that development is moving along almost too smoothly. On top of all this there are multiple, different GUIs that are to interact with the subsystems and what one GUI does the other GUIs (if applicable) are to respond accordingly. Either by displaying the info or acting on the change. The GUIs are to be able to connect and disconnect from the main system at will and any actions they performed are not to be lost.

      We are using Linux as our development and deployment platform. I am heavly using System V IPC. If it wasn't for "Design Patterns" I would not have known where to beging. It opend my eyes to many different aspects of OOA OOD and OOP that other books just simply fell short. "Pattern Hatching: Design Patterns Applied" will be the next book that I add to my library. For the GUI I am using GTK. It fit so nicely in its OO approach that I couldn't pass it up.

      I'm sorry if the above text is a little confusing but I cannot divulge any details due to the fact of the paranoia of managment of the competetors (Which in this industry is well founded)

      --
      If at first you don't succeed, skydiving is not for you.
  4. I am shocked by duplex · · Score: 5
    by this review. Having read the Design Patterns from GoF and the "System of Patterns" by some five guys and this little book. this one is definitely the most down to earth one. The subjects of destroying singletons is a very important and overlooked issue and the fact that singletons can be misused is in no way detrimental to Pattern Hatching. The examples from the book often touch on problems I encountered myself when coding.

    The fact that the book is focused on C++ stems from the aim of the book that is to show the patterns applied. If he settled for some abstract or rarely used lingo would that be showing design patterns applied?!

    I think the discussion on the Observer is the best I have ever read and the treatment is solid and all tradeoffs are discussed. It's a pleasure to read and very enlightening approach to the Most Misused Pattern in the World(tm).

    By all means ignore this review and pick up a copy. It's a masterpiece from a guy that really knows what he's on about. If you understood the GoF book you'll find this a great addenum. This book deserves a place next to books like Writing Solid Code and Code Complete.

    I'm embarrased to see slashdot giving this book such a poor review. The book deserves all the praise and I strongly suspect that the reviewer never tried applying desing patterns. Pattern Hatching shows you how it all fits together. It doesn't discuss individual patterns but brilliantly shows you how they all interact. Buy it!

    1. Re:I am shocked by SimonK · · Score: 2

      I wouldn't say this review was poor. The reviewer had an issue with the author's emphasis on C++, and I'd agree about that. There are several OO languages in reasonably common use (C++, Java, Delphi, even VB, with fairly large amounts of code in Smalltalk, Eiffel etc still in existence), and among object orriented languages as a group C++, while possibly the most commonly used (although newer projects tend to be in Java), is distinctly eccentric in several ways.

      If the author intended to make his advice generally applicable, it was possibly unwise to pick a language who features and terminology are so unusual.

  5. Need more help... by Carnage4Life · · Score: 2

    I've read design patterns and agree that it is one of the most useful books I've ever read (right up there with books by Scott Meyers, Sedgewick and Bjarne Stousstrup)...Click on the Amazon link to read several comprehensive user reviews of the book just in case the link above seemed rather dry to you.

    PS: Please do not buy this book on Amazon. Go to Addall and find a vendor. Please keep up the boycott...thank you.

  6. Um.... by Tower · · Score: 3

    Why does the "ThinkGeek" link point to http://slashdot.org????????

    --
    "It's tough to be bilingual when you get hit in the head."
  7. Garbage collection languages by Tim+Behrendsen · · Score: 2

    I found the reviewer's bias toward languages with built-in garbage collection a little annoying. For some projects it's appropriate to use a language with garbage collection (web scripts), and sometimes it's not (operating systems). While he may be "amused" by the need for manual deallocation of memory, he should understand that it's generally far more efficient.

    Unfortunately, I think the reviewer doesn't have much experience with low-level system programming to understand these trade-offs. Until he does, he should resist making judgements.

    P.S. This is not to defend C++ as a language...


    --

    1. Re:Garbage collection languages by dsplat · · Score: 2

      I found the reviewer's bias toward languages with built-in garbage collection a little annoying.

      The one thing I find myself wishing for most often with garbage collection is a feature that is available in most Lisp implementations: a function to explicitly trigger the garbage collector. This gives me all the power that I usually want in a language with explicit storage allocation and deallocation. I often just want the ability to say when it is convenient. That is a bit of knowledge that programmers almost always have and the runtime library frequently doesn't. So right before a big task that is going to take a while and chew up memory, or right after a big response gets handed to the user:

      (garbage-collect) ; Emacs Lisp dialect

      --
      The net will not be what we demand, but what we make it. Build it well.
    2. Re:Garbage collection languages by Tim+Behrendsen · · Score: 2

      It sounds interesting, but where has this been demonstrated in real world implementations?

      Since objects can be moved around by the memory manager, you have to have "handles" with double pointers, locking, all kinds of nonsense.

      It sounds good in theory, but I would be interested to know if it's ever been used in a real application outside the lab.


      --

    3. Re:Garbage collection languages by Tim+Behrendsen · · Score: 2

      Note that you don't need to use "handles", because in all of these languages there's no such thing as explicit pointers, so it's possible for the memory manager to know where all the pointers are and update them transparently.

      Well, OK, maybe you're not using handles at the language level, but so what? There is still all that logic under the hood, and that is a big performance drain.

      All the languages you have named (including (notoriously) Java) are not practical for any sort of large-scale application where performance is a concern. You haven't really given any evidence to support that GC is practical for a performance-critical major application.

      In fact, I asked if this GC method had ever left the lab, and it could be argued that Lisp and Smalltalk have never left the lab. :)


      --

    4. Re:Garbage collection languages by Tim+Behrendsen · · Score: 2

      Just out of curiosity, which side are you on? :)


      --

    5. Re:Garbage collection languages by Tim+Behrendsen · · Score: 2

      No, I mean you don't have handles at the implementation level. And the advantage of putting that logic into the compiler is that you only have to get it right once, by the compiler authors. This is sometimes called code reuse. ;)

      Well, I suppose you could keep a list of all the references to the object, and update all the references when the object moves. The does mean you need all sorts of locking nonsense if you want preemptive multithreading.

      I must admit you've given some food for thought about whether a practical GC could be done. I suppose the logical question is why hasn't it been done for a C++ compiler? If ever a language cried out for GC, it's C++.

      Common Lisp is very much a practical language...

      Well, I've never programmed a phone switch, so I can't say about that one. And I'm sure it may have snuck in as a scripting language in a game or two, and maybe some rogue programmer did something in an operating system.

      But the question is whether it should have been. You can't deny that C is by far the most dominant language for doing high-performance system programming (leaving out numerical programming in FORTRAN), and there is a reason for it.

      As for AI, don't cite that to me as a "practical" application, or I'll laugh at you. (AI is to Science as "1,2,3,Many" is to Mathematics).


      --

    6. Re:Garbage collection languages by Tim+Behrendsen · · Score: 2

      This is what I love about many of you people: You're so classy and gracious.

      Unlike you, I was not born knowing all human knowledge, and I even occasionally like to learn something. My ego is not so fragile that I can't admit when I learn something.

      My "pontification" on the performance is based on actual experience. There are a lot more factors than just performance that come into play when using a GC language. I find it interesting that there are so potential solutions to the historical performance problems, but this does not mean that it's appropriate for all problems.

      I might also point out that I'm am FAR from convinced that using Lisp or Smalltalk (which have notoriously bad performance compared to lightweight languages such as C) as an example is proof of anything.

      The fact that you think these problems are so simple that you just "RTFM" instead of actually using your brain and experience tells me you have very little of either.


      --

    7. Re:Garbage collection languages by Tim+Behrendsen · · Score: 2

      Other than if I grant that GC could utilize stack allocation in some cases in the second statement, what is wrong with my first statement? GC will be slower than manual allocation, because there is overhead to doing "something" (tracking references) rather than doing "nothing" (not having to track references).

      The burden of proof is on you to demonstrate how a method of GC can be as fast or faster than manual allocation.

      Incidently, I'll even grant to you the fact that the reason Smalltalk and Lisp are slower relative to C is not completely GC, but just the nature of the languages. Still, that does not prove that GC is as fast as manual memory management.

      The other thing is that I feel I'm getting a bad rap here. I'm not against GC in languages, but there are cases where you don't want the unpredictability of GC and manual memory management makes sense. Are you trying to say that GC is appropriate for all problems?


      --

    8. Re:Garbage collection languages by Tim+Behrendsen · · Score: 2

      You said that it would be "trival" to prove that GC is slower than hand management. If its trivial, it should be easy for someone of your broad knowledge of computer science to provide it. If you're going to make that kind of statement, the burden of proof is on you.

      You're not paying attention. I gave you the proof. Someone with your awesome abilities should be able to blow it down in one whiff.

      CMU floating point bench marks

      LOL! A prime example of "lies, damn lies, and benchmarks". A trivial floating point benchmark proves absolutely nothing. Of course that type of problem is going lend itself well to compiler optimization. I could write similar things in APL, and it would probably be very fast, but that would say nothing about APL's viability for general problem domains.

      You would be a bit more credible if you gave me a non-trivial program written in both languages. Say, a C++ compiler and optimizer. Or how about a Photoshop-like graphics manipulation tool. Or heck, how about a version of Quake in Lisp?

      What is your theory on why people don't use Lisp for any non-trivial project? Is my apparent level of ignorance so rampant in the industry?

      You must be in academia.

      Quote from Harlequin: "By supporting a variety of manual policies and tuning, Harlequin delivers significantly better performance than can be achieved with other vendors' existing 'one size fits all' allocators."

      Apparently they suffer under the same delusions that I do.


      --

  8. by SEWilco · · Score: 2

    I should look in the current SlashCode and fix something myself. Sometimes there isn't time for all trivial reported problems to be fixed.

  9. Ritual/taboo programming by Animats · · Score: 2
    Too much of this "pattern" stuff is an attempt to codify workarounds for language problems. There are parts of C++ that are just wrong, mostly for legacy reasons. (It's not so much C legacy any more; C++ has its own legacy problems. For example, "this" ought to be a reference, but references went in too late.)

    Even worse is the "standard template library". That has become a playground for language fanatics. People are trying to implement LISP lambda-expressions using C++ templates, which is an example of using the wrong tool to implement a mediocre idea. The STL has resulted in a number of programming paradigms that are very complicated, bug-prone, and involve coordination of items far apart in the source text.

    "Patterns" are being promoted as an answer to some of these problems. Just follow the ritual, avoid the taboos, and it will work. Don't try to understand why.

    Anyone remember how the Symbolics LISP gurus messed up Common LISP, by insisting that all the crap their specialized hardware could support should go into the language and libraries? The STL crowd is doing that to C++. It's not good.

    Humor item of the day: The Symbolics machines had the "MIT Space Cadet" keyboard, with a SHIFT key, a CNTL key, a TOP key, a META key, a SUPER key, and a HYPER key, all used as shift keys and all usable together. This came from a joke attempt at MIT to outdo Stanford, where the SAIL machine had TOP and META. Symbolics shipped that keyboard standard to customers. Symbolics is out of business.

  10. What do you think? by Dacta · · Score: 2

    I'll let you try and work that one out for yourself.