Decoupling Gameplay via the Observer Pattern

Wow! The last two chapters were full of pointer craziness. Those two chapters combined, cover what are probably considered the hardest parts of C++. While all design patterns deal with pointers and using virtual functions at some level, it doesn't get much more difficult than what was covered in Chapter 7, Improving Performance with Object Pools and Chapter 8, Controlling UI via the Command Pattern.

In Chapter 7, Improving Performance with Object Pools, we went very low-level into the guts of C++ memory. This involved casting and strange pointer manipulation that most people tend to avoid. In Chapter 8, Controlling UI via the Command Pattern, we dealt with controlling the UI, which is more high-level. However, we learned how to control C++ objects and their methods in a way that allows us to create flexible code, but can also be very confusing.

If you feel comfortable with those chapters, then you are doing great. If you felt that those topics were a little difficult, you are not alone. Either way, you should be excited to know that this chapter covers a pattern that is easy to understand, easy to implement, and easily allows us to decouple our core systems from the gameplay specific code that is likely to change often.

In this chapter, we will cover a pattern called Observer, which is used to connect objects together in a decoupled way. As you will see, it is very simple to implement and can be applied in many places throughout our code base.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.225.255.187