All right.
So let's talk about the observed design pattern.
Now let's suppose that we have a Symbol object like for example a person with an H field so we can make
a class called person and this person is going to have a field called age.
Now in order to be able to track changes in age what we need to do is we need to basically have getters
and setters so that we make it public section.
And here is where we would have the Gethers and said Is now the goal of the observer design pattern
is to get notifications of particular changes in the system or just particular events happening in the
system and in this case what we want to track is we want to track every single instance when somebody
changes the age because who knows we might want to give the person who's age has increased certain additional
rights like an ability to vote for example or in the Botti to drive a car so we're going to implement
this by using the observed design pattern which has two components to it.
So the components are the observer and the observable.
So the observer is that thing which wants to monitor something and the observable is the component that
is to be monitored.
So in this case our person is the observable and the observer is something that we are going to build
and in actual fact we're going to begin by defining the interface of the observer.
So what is an observer and what does it actually need to provide in terms of its API.
Well let's define a very simple base class.
We're going to have an observer.
So this base class is going to have a template argument
where T is the type of the object we're actually observing.
So here are we going to have just a single function.
Now what I'm interested in is I'm interested in observing changes to types fields.
So that's what we're going to have here.
We're going to have a virtual void function called field changed.
And whenever the field changes we're going to get some information about whose field has changed and
what's the name of the field.
So we're going to have a reference to the source of the object which actually changed.
And we're going to take the name off of the fuel that changed.
And yes I need the string Ketterer for this one.
So having constructed this kind of interface what we can do is we can actually start building some sort
of observer which would for example get notifications on changes in the person.
So the way this would be done is fairly simple to be honest.
So we'll make a simple observer which will print stuff to the console.
So let's let's do this let's have a structure called Konsole person observer is going to implement the.
Let's actually go in here.
It's going to implement the observer off person interface.
And here what we're going to do is we obviously need the header are we going to generate the appropriate
function.
And here we can print out certain information about the fact that a particular field of person has changed
to something so we can see out the person's field name
has changed too.
And then we can get the actual value depending on the name of the field.
So that might seem a bit crude but that's how we're going to do this.
So for example if the field name is equal to a page we're going to see out we're going to see outsource
DOT gets h and then towards the very end we'll put a line break and a dot.
So this is how you would implement the observer.
And of course in order to actually be able to use this observer the person class has to play ball as
well so the person class has to explicitly support this paradigm and that's what we're going to implement
next.