#100DaysOfCode in Python Transcripts
Chapter: Days 13-15: Text-based games (and classes)
Lecture: Modeling concepts: Inheritance, classes, and objects

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Before we actually write the code and get into the syntax of working with classes, I want to just talk briefly about the idea of two things:
0:09 inheritance and the difference between classes and objects. So, in our game we have this concept of a creature, how it'd be like the tiger,
0:17 that would be, say, the dragon, the bat that the wizard defeated, things like that and in fact, the wizard himself is also a creature.
0:26 This creature concept has the basic ideas of what it means to be an actor in the game. It has, let's say, a level, a name,
0:34 and it can sort of defend, at least against being attacked. But we can, say, well, there's special things
0:42 in the game that have more distinction than that. So, there's a tiger, maybe the tiger has a special way to defend and so
0:50 its mechanism for defense, it's a little bit different than, say, a toad or a standard creature. We have a dragon, maybe the dragon takes into effect
0:58 whether it can fly, whether it has scales, whether it's fire breathing, things like that. And this aspect of the dragon means
1:08 we probably need to model those features that make it different from a creature separately. So it's like a specialization of this creature.
1:16 Now also, the wizard itself. When you model like this, you're modeling what's called an is-a relationship. So, the tiger is a creature.
1:24 The dragon is a creature and so on, right? So tigers are creatures. So we're going to model this type of thing
1:31 and I'll show you how simple this is to do in Python. The other important distinction to make over here is, let's look at this wizard concept.
1:38 You need to think of these classes that we're going to define. I haven't shown you how to do it yet, you may know but if you don't know,
1:44 you got to think of these as blue prints. Let's think about a tiger for a second. There's a tiger that's in the San Diego Zoo,
1:52 there's a tiger that's in the wild, in the jungle. These tigers were created from the same blue print, from the same DNA.
1:59 That's kind of like the class. But the actual tiger in the zoo and the tiger in the forest, those have different properties
2:05 and they evolve in different ways over time. They're not exactly the same thing. So you'll see, the same thing is happening here in codes.
2:13 So we have this line gandalf = Wizard() and this line is going to create a new wizard from the blue print of the class.
2:20 It's going to create what's called an object. And over here we're going to have sort of in memory this thing, it knows it's a wizard
2:26 and it knows its name is Gandalf, and it's Level 70 and those can change, sort of on their own. But the evil wizard we're creating, it's going to be
2:33 a separate thing out there in memory called evil wizard with the name and the level 100. And once they're created they can
2:40 be changed and evolve independently like the wizard that is Gandalf can level up to 71 and it would have no effect on the evil wizard.
2:47 The thing at the bottom of the two arrows, the wizard Gandalf and the wizard that's evil, those are objects.
2:53 The modeling blue print thing at the top, those are classes. Hopefully that illuminates the confusion around those
2:59 which is always hard when you're getting started.

Talk Python's Mastodon Michael Kennedy's Mastodon