Implementing the Observer Pattern in C++ – Part 2

In part 1 of this article I presented an Event/Callback library intended to support the Observer pattern and hinted that it had some limitations. The library was based on the following Event class template: template<typename Arg> class Event { public: // Iterator type definition. typedef … iterator; // Destroy an Event. ~Event(); // Attach a… Continue reading Implementing the Observer Pattern in C++ – Part 2

Implementing the Observer Pattern in C++ – Part 1

Introduction The Observer design pattern is described in the “Gang of Four” book [Gamma] as a method of propagating state changes from a Subject to its Observers. The key feature of the pattern is that Observers register with the Subject via an abstract interface. The existence of the registration interface decouples the Subject from its… Continue reading Implementing the Observer Pattern in C++ – Part 1

Template Titbit – A Different Perspective

Background Oliver Schoenborn’s article, “Tiny Template Tidbit”, in Overload 47 illustrates some of the wonderful things you can do with templates. I particularly liked the way it described the thought processes Oliver went through when designing some curve-fitting software and his clear explanation of the problem he set himself. Whilst reading an earlier draft of… Continue reading Template Titbit – A Different Perspective

Supporting Threads in Standard C++ – Part 3

Recap The previous articles in this series on threads offered two suggestions: Use a thread function interface class to separate the application-specific code from the thread library facilities (the Thread-Runs-Polymorphic-Object design). Use a Handle-and-Reference-Counted-Body technique to manage the lifetime of objects representing threads. The resulting thread model can form the basis of a useful thread… Continue reading Supporting Threads in Standard C++ – Part 3

Supporting Threads in Standard C++ – Part 2

Recap The first part of this series of articles on threads addressed what I called the function signature mismatch problem. The thread library needs to allow an arbitrary user-defined function to be run asynchronously with respect to other threads. That function could have any number of parameters of any type, but the thread library can… Continue reading Supporting Threads in Standard C++ – Part 2

Supporting Threads in Standard C++ – Part 1

Why Threads? Shortly after the C++ standard was announced I read an article explaining what the standardisation committee will do next. There is still work to do, it said. Although the standard is not allowed to change for 7 years some parts will need to be clarified and ambiguities and inconsistencies will need to be… Continue reading Supporting Threads in Standard C++ – Part 1

The State Pattern – A New Implementation

Introduction In their book, Design Patterns, Elements of Reusable Object-Oriented Software, Gamma, Helm, Johnson and Vlissides describe a design pattern called State. The State pattern allows an object to change its behaviour when its internal state changes. For example, suppose we have a Button class with a (public) member function, Press(). The first time the… Continue reading The State Pattern – A New Implementation

DDT

A mosquito was heard to complain That the chemists had damaged his brain. The cause of his sorrow Was para-dichloro- Diphenyl-trichloro-ethane.