Now, if you're just learning to code, you've seen this word class and you've probably wondered, what
does it mean?
Well, it's a way of grouping stuff logically.
So if we had a class that represented a dog, we could put some variables in it.
Let legs equals four because dogs have four legs and let tail equals true because they have tails.
We can also have a function called Wolf, which prints out Wolf for us.
So what this class does is illogically arrange all of the properties that a dog has and all of the functions
that a dog has.
Classes are the fundamental structure that we use to organize our code.
So you might have something like a class to fetch a Eurail from your observer.
You'll have a class to share something via Facebook.
You'll have classes to do all of these things.
And in fact, well, I'm not going to say that's a class because I don't think it is, but it is I think.
Ignore me on that.
I have to explore that a bit more anyway.
Class dog is.
A blueprint, right, a blueprint doesn't exist.
Yes, I know you can see the code, but it doesn't actually exist yet as an object because blueprints
make objects, classes make objects.
So when you hear the word object in programming, it's because someone went to a class called Doug open
and close some brackets.
Now it's an object.
Now the dog is real.
Left froglet dog equal to dog.
OK, so now that I have that object, I can start making it do whatever I want.
I would like you to, Wolf.
And so when I hit play, that is going to print out Wolf for us.
OK, so a class is a fundamental way of organizing things.
Now, what if I had a cat?
So I'm just going to copy the first part of my notes here.
And this cat is like the dog, it has legs, a tail, it has a name and it has meow.
Now legs and tails always stays like that, basically.
Cat's always meow, right, but what about this name?
How do we fill that in?
Because every cat has a different name.
What we can use is the Init function.
Now in it is a special function that gets called whenever the class creates something from itself,
whenever this blueprint turns into a cat object.
The in it allows you to pass arguments over just like any other function, and then once you've passed
the argument over, you can do stuff with it so you can say set self-taught name self simply refers
to the current object of this cat.
And we the reason we use it is because we have a name here and a name here, and we need to distinguish
which one we're talking about.
So this one refers to that.
And this one refers to that, right, so we're setting the name of this object to the name we've passed
in and so we can have our cat is equal to Cat.
And you'll notice this gives an error because it says I need to have a name for the in it parameter.
So we say, fine, you may have Felix.
Now, when we hit play, we get our cat called Felix, how do we know he's called Felix?
But we can say cat dot name.
And there we have Felix passed in, so this in it actually is short for initialise.
It's the thing that creates the object from the class, if you like.
The thing that kicks it all off well, it doesn't kick it off, does something further down the chain.
But we don't need to worry about those specifics right now.
So I've got some homework for you with classes.
And here it is, create a class for an accounts package, account software.
I want you to have two variables.
One store's income, one store's expenses, just integers.
Create two functions that add the expense variable and the other one to add to the income variable.
OK, this is the first part of the homework we're going to carry on with this class concept.
So that's probably not that difficult.
Go ahead and give that a go.