Python for the .NET developer Transcripts
Chapter: Course conclusion
Lecture: Object-oriented Python review
0:00 Next up on our Pythonic journey
0:01 were classes, and objects and object oriented programming.
0:05 And you saw that Python has a rich, proper
0:08 object orientated programming model.
0:11 We have private data, we have public data, we have methods
0:14 we have abstract methods, we have properties.
0:16 It's not as full featured as C#'s object orientated model.
0:21 For example, we can't reasonably have protected values
0:25 without conventions.
0:26 We do have these private values here
0:28 but protected is more of a suggestion.
0:32 In Python, you also don't have, for example
0:34 virtual versus non virtual methods
0:36 and you can override the virtual ones
0:38 but not the non virtual ones without a warning.
0:40 Right, so there are some things that are not there
0:42 but it's most of the important stuff
0:44 you're going to use day to day, it's there.
0:46 So here we're going to define a car class that's abstract
0:49 so it derives from ABC, abstract base class
0:52 remember how we imported that.
0:54 One of the bigger differences is the way we define fields
0:57 is in the constructor
0:58 or in the dunder init initializer method here.
1:01 So we say self dot model name equals model name
1:03 and that actually defines the field
1:05 as an instance variable on this type.
1:08 Right, in C# this would be outside of the constructor
1:11 you would define private field such and such
1:14 or public field such an such.
1:16 Once you get used to this, though, it's totally fine
1:18 it's just different.
1:20 We also have a regular function
1:21 we have, which is drive.
1:23 We have a property, which is is electric
1:25 so that's a computer property.
1:27 And we have abstract methods as well
1:30 and that's our refuel.
1:31 You want to drive from car class and be implemented
1:33 or instantiated you've got to implement refuel.