Implementing interfaces
The next thing to consider is the implementation of the Observer pattern. In the above example, the Subject and the Observer were designed to be interface classes. C++ doesn't have a language feature that supports interfaces but that doesn't mean we can't write code that uses them.
An interface is a class that contains no data members and has no method implementations. C++ does allow for the concept of abstract base classes. This is any class that marks at least one method a pure virtual, but using the = 0 notation. This means that the class can't be instantiated and instead must be derived from. This is different from an interface because abstract base classes can contain member data as well as implementations for ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access