O'Reilly logo

C++ All-in-One For Dummies, 3rd Edition by John Paul Mueller, Jeff Cogswell

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required