Re: Observer Design Pattern
boaz_sade@yahoo.com wrote:
Thomas J. Gritzan wrote:
Thomas J. Gritzan schrieb:
boaz_sade@yahoo.com schrieb:
Next their Template and Algorithm patterns - do you really think that
we need those?
The Template design pattern is used in the STL all over the place:
std::sort, std::copy, ...
Err, not std::copy.
Used in:
std::sort, std::for_each, std::find_if, std::transform and the like...
Then eigher you don't know how those algorithms are implemented, or you
don't know the algorithm design pattern from the GoF book - take you
pick :)
He got the latter wrong. sort, for_each, find_if, transform, &c. are
all examples of the Strategy pattern.
There is NO correlation between the STL and design pattern GoF.
Either you don't understand design patterns or you don't know the STL,
take your choice. :-) Actaully, I don't think you do get to choose. You
look at the implementations in the Design Patterns book and assume that
they are saying that those are the only way to implement them and
that's just plain wrong. That's why I told the OP that implementing a
"Design Pattern Library" can't be done in general. There are too many
different ways to implement the patterns discussed.
Even with a pattern as simple as Observer, I showed two completely
different ways to implement (one using runtime polymorphism and a pull
approach, one using tempates and a push approach.)
The Iterator pattern is fundimental to STL and as I show above,
Strategy is used all over the place as well.
Based on one of your other posts, you don't seem to think that STL uses
Iterator. You need to broaden your mind and look again.
GoF Iterator C++ Iterator
First() it = container.begin()
Next() operator++()
IsDone() it == container.end()
CurrentItem() *it