Chapter 6

Building with Design Patterns

In This Chapter

arrow Understanding what design patterns are and how you can use them

arrow Implementing an Observer pattern

arrow Building a Mediator pattern

When you work as a software designer, eventually you start to notice that you do certain things over and over. For example, you may get into a pattern of getting mad and shutting off the computer. But that’s not directly related to software design.

For an example related to software design, whenever we need to keep track of how many instances of a certain class get created, we always create a static member variable called something like int InstanceCount; and in the constructor, we include a line that increments InstanceCount; and in the destructor, we put a line that decrements InstanceCount. Further, we typically make InstanceCount private and include a static method that retrieves the value, such as int GetInstanceCount().

We have used this design so many times that we know it works. The first time we used it, we had to think about it and how we would design and implement it. Now, we barely have to think about it; we just do it, sometimes even when we’re driving down the road. Well, maybe not then, ...

Get C++ All-in-One For Dummies, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.