Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Design pattern

Observer Design Pattern:


Source: https://www.youtube.com/watch?v=rF3TfkknQK0

Observer Design Pattern defines one to many dependencies between the Objects, so that when one
object changes its state, all its dependents are get notified and updated automatically.

E.g Lest assume we have a class called Subject, this class will have a List<Observers> who registered for
to get notified, when the state of data member changes its state/value, the object will notify all the
objects which are dependent ( List<Observers> )on this.
Smart Pointers
A smart pointer is a wrapper class over a pointer with an operator like * and -> overloaded. The
objects of smart pointer class look like a pointer but can do many things that a normal pointer can’t like
automatic destruction (yes, we don’t have to explicitly use delete), reference counting and more.

The idea is to take a class with a pointer, destructor and overloaded operators like * and ->.
Since the destructor is automatically called when an object goes out of scope, the dynamically allocated
memory would automatically be deleted (or reference count can be decremented). Consider the
following simple smart ptr class.

You might also like