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