CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    May 2001
    Location
    Silicon Valley
    Posts
    113

    Question Is Template Method design pattern and Hook the same thing by different names?

    Colleagues,

    Is Template Method design pattern and Hook the same thing by different names?
    Odd thing is, when I look up hook design pattern on Google, 90% of search results go to pages that describe the Template Method design pattern. I'm trying to find the historical explanation for this. Is Hook a non-OO spiritual precursor to Template Method?

    What had prompted me to look into the Hook pattern was this Miro Samek's app note about pattern which he calls "Ultimate Hook". This app note is about message handling by hierarchical state machines. Samek didn't invent the term "Ultimate Hook", though. It was mentioned in 1995 by Petzold in his book on Win 95 programming. The context was plain C. WinMain(...) and WndProc(...) without classes.

    Any suggestion, insight or reference is really appreciated!

    Cheers,
    - Nick

  2. #2
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,765

    Re: Is Template Method design pattern and Hook the same thing by different names?

    Quote Originally Posted by kender_a
    Samek didn't invent the term "Ultimate Hook", though. It was mentioned in 1995 by Petzold in his book on Win 95 programming.
    It sounds like the terms are synonymous due to having been named in the literature at roughly the same time. (The GoF book was published in 1995.)
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  3. #3
    Join Date
    Jun 2015
    Posts
    208

    Re: Is Template Method design pattern and Hook the same thing by different names?

    Quote Originally Posted by kender_a View Post
    Is Template Method design pattern and Hook the same thing by different names?
    I wouldn't say so. Both are based on the general idea of a hook (a place in code which serves as an entry point for some external code) but that doesn't automately make them the same.

    Hooking is everywhere (at various levels of abstraction): callbacks, delegation, macroes, virtual tables, indirect dispatches, virtual functions, the CRTP idiom, dependency injection, and even first-class functions.

    Looking at the intent of the Ultimate Hook pattern I would say Ultimate Event Handler would be a more telling name.

  4. #4
    Join Date
    Jan 2010
    Posts
    1,133

    Re: Is Template Method design pattern and Hook the same thing by different names?

    In addition to the above: the Template method pattern is more about defining a concrete sequence of steps for an operation/algorithm, but with the details of each step abstracted away, so that subclasses can provide different implementations within the "frame" established by the base class.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured