April 2017
Beginner to intermediate
394 pages
9h 16m
English
Let's look at a code example to understand this pattern better. There are a few different ways to implement this pattern, so we will discuss implementation strategies along the way:
class Observer { public: virtual ~Observer(void) {} virtual void Update(float currentHealth, float maxHealth) = 0; };
We start off with our Observer interface. As always, we make our destructor virtual. The only method we need is an Update method however, as always, the name isn't important. This is the method that the Subject will use to notify the Observers that something has changed. One thing you might notice is that the update is very specific. In this case, it has two floats as arguments. This is a dependency that might change ...
Read now
Unlock full access