Dangling references
The first major problem that everyone should be aware of is the problem of dangling references. We must ensure that the pointers held by our objects never become invalidated. The best way to understand this problem is to look at the Command pattern and compare it with the Observer.
The biggest difference between the Command pattern and the Observer pattern is a difference in ownership. In the Command pattern, the client or user of the command owns a pointer. This means that the client is responsible for deleting the command. The reason this is important is because no other class owns the command pointer, so it should never become invalidated. In the Mach5 Engine, the UIButtonComponent owns a command. It deletes that command ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access