O'Reilly logo

C++ All-In-One For Dummies®, 2nd Edition by Jeff Cogswell, John Paul Mueller

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

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

  • Implementing an Observer pattern

  • 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 mad and shut 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 we know that 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, but we do use it when we're designing software. Thus it's a design pattern that we use.

Way back in 1995, a book came out that became an instant best seller in the computer programming world. It was called Design Patterns: Elements of Reusable Object-Oriented Software, by Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides. The four ...

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