-
July 11th, 2015, 09:03 PM
#1
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
-
July 12th, 2015, 12:18 AM
#2
Re: Is Template Method design pattern and Hook the same thing by different names?
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.)
-
July 12th, 2015, 04:44 AM
#3
Re: Is Template Method design pattern and Hook the same thing by different names?
Originally Posted by kender_a
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.
-
July 14th, 2015, 02:51 AM
#4
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|