So the first thing we need to understand in here is the concept of or pick what is or the opiate stands
for object oriented programming.
And it is something that you have been using throughout the previous lessons but we never got the chance
to talk about it now or be cannot really be explained on its own.
I'd rather if I talked about in contrast and comparison to other programming paradigms to the best of
my knowledge there is crankily four different programming paradigms.
They are all P functional imperative and logical now functional programming essentially means program
is a series of mathematical formulas that they work next which other imperative means program is a series
of instructions that each instruction does something and they follow the program and then that is the
logical which is essentially modeling information on the relationship between them all.
PS In your concept object oriented programming essentially means that you have instructions that they
build something from those instructions you build the things that you want and you have the relationship
between them.
So an instruction that we call a class knows how to build a car and then from there you make your first
car and then your second car Angleterre car and each car has a set of attributes and a set of methods.
So each car has things such as the color of the car or the maximum the speed of the car and then it
has some functions such as drive change year stop.
Now the advantage of all p is that every object that is made of a class is independent from the other
instances of that class and they can all interact with each other or with other objects.
To put these concepts in a better context lets go ahead and have a look at some images.
I highlighted some images in here.
So the first example of all IP is a class of a car.
So it might classify a car has some method such as refuelled or get fuel or get set speed or get speed
or drive and it has some attributes.
The current amount of fuel the maximum speed this car can go.
And as you can imagine this class is what we call a blueprint for building different cars.
So from this class I can make my object one of which is a class that does something.
Now if you're trying to relate this to the things that we have seen so far this is unnecessary.
It knows how to make a string.
It knows how to keep some text values in it.
And then you can make as many of those as you want.
Eating is essentially the same way it's an endless array it's a class of N.S. mutable dictionary so
on and so forth they each have some attributes and they each have some methods.
My next example is this one.
There is a class building that knows how to produce different buildings and then from that if we make
one empire state that's an instance of a building or my other class is dog.
And from the dog class we make this particular dog called Lassie which she said somewhat seriously then
of course by setting different attributes on different instances of different objects.
We obviously make different models we have different things that they interact with each other just
like you know if you are making our users in some of the previous lessons then for each user We had
a different set of information different name two different photos so on and so forth.
And obviously my last example is a computer that from a computer class we can make this particular computer
that does particularly in our settings and actually it's not all play has a lot of different jargon
in it.
We have to talk about classes.
We have to talk about that abstraction encapsulation inheritance information hiding polymorphism and
there's some other stuff that we'll talk about as well.
So we have a long way to go to understand every bit of this.
One good news is we have seen most of this in practice so far we have used classes.
We have made objects of them.
If you haven't seen inheritance you then know its name but we have kind of seen it.
Now before I close this lesson I move on to actual programming in Axford.
I want to show you one more example of classes and objects.
So I have developed this very crude you know demonstration.
So I imagine this example is for real life situation is for a human that needs to speak French from
time to time needs cooking and also needs access to a car.
Now the way it works is this.
Every once in awhile I get a phone call and somebody is talking French so I need someone to translate
that for me or a neat way of translating French because I don't speak French or every once in a while
don't need to be cooking something and every once in a while I need transportation so I need access
to a car.
So if you've really not impressive programming paradigm what you would do is when they get a free talking
guy over the phone you would write a program that translates French to say English.
So you would write the entire set of instructions that does something for us then we needed to cook
something that would write the entire set of instructions that does the cooking and so on the same thing
for transportation you know an opium mother we do things a little bit differently in all people.
When we have a need for someone that speaks French we get an object from French that we call it French
translator one.
So we get an instance of that class that is about translating French.
And then if later on I need to cook something I get my cook the first cook shows up and does something
for me that I need to move on but then I get an access to a car.
Now here is a challenge that often you know you have to think about it.
So what happens after a while I need another French translator I'm somewhere else in my program where
I'm in a different class when I'm writing a totally different thing.
So I need to get another French translator and perhaps another one.
And so on and so forth.
I need to get access to more cooks and more cars and more of almost everything simply because in the
concept of all the constantly adds more and more instances of differing classes.
So here we run into an issue and that issue is the memory management.
If this was a real life example and I had to hire a cook to cook food for me and then the next day I
had to hire another cook.
And then by the end of the month I would have 30 cooks sitting at my home and that's what we call memory
management.
Once we get an object of a Class A does something for us such as doing a French translation the very
first time then we say well your work is not deallocate you because I don't need that anymore.
And then we do the same thing so on and so forth with every object that we don't need.
Now once we get rid of all of these things what is intact is these classes the blueprints for making
another cook or blueprint for making another French translation or another car that is stays intact.
We can always access them but those objects we just use them temporary and then ones we don't need them.
We get rid of them.
It's very similar to when you have a button and you have a text field.
You say get the text fields text put them in a string and that string printed so that NASA string it
gets initialized and allocated for a short amount of time does something and then gets deallocated.
So we don't have to worry about the memory that you're essentially investing or let's call it a vase
thing and then we'll talk about this in far more detail when we talking about the memory management
in a few lessons from now.
So in a nutshell that's a concept for object oriented programming objects such as core one made of classes
such as car that knows how to make different cars every object based on their parent.
They have a set of things they can do that we call functions in a case of a car such as changing gears.
In a case of a cooking light such as cooking a certain recipe and they have some attributes in case
of a car that's would could be the color in case of a translation that's cheap Be it could be the language
that is going to translate for us.
So on and so forth.
So with that in mind I'm going to move on to our next lesson where we can actually begin writing our
own classes.
We have been using them so far but this time we're actually going to write our own version of things
and get a better sense of how all works in Strief in Objective-C.