In this chapter, we have examined four more behavioral patterns. They are a bit more complex than the patterns from the previous chapter, but they also help a lot with organizing the code and are well worth your consideration.
The iterator pattern is well-known to Delphi programmers. Most of you know how to write a
for..in loop, even though the implementation details hiding behind this construct may not be your biggest concern. In this chapter, we have also explored the other part of iterators, namely, how to use them as a tool for writing generic algorithms.
This chapter continued with the visitor pattern, which is in some aspects iterator's counterpart. Unlike the iterator, this pattern wasn't designed to walk over data structures, but to iterate over complex object structures. With a proper implementation, it allows us to open a small window into object internals and use it to write extensions that enhance existing objects.
The observer pattern, also know as publish-subscribe, is...