Python for the .NET Developer Transcripts
Chapter: OOP: Object-Oriented Python
Lecture: Object-Oriented Python

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Let's talk about object oriented Python writing classes, inheritance, creating objects modeling things like, well, you are probably pretty
0:09 used to from C#. It turns out that Python has excellent class inheritance object oriented support.
0:17 So, let's talk about some of the features that Python has. Everything is an object. Now, you can sort of say this
0:23 also for .NET or for C#, everything is an object there as well. Everything derives or can derive from System.Object
0:31 That's almost true for C#, because you have value types and reference types in order to treat the value types
0:37 as an object, you have to box them and unbox them and there's some complications in there. In Python, truly everything is a reference type.
0:45 Even the numbers are reference types. And all of those reference types derive from the object class.
0:53 We have instance methods and we have static, also something called class methods. These kind of behave similarly.
0:59 just like we have in C#, you can create an instance of an object and it has its behaviors or the type
1:04 has, like, static behaviors, got that, properties. Remember the days when you used to write get value and
1:10 set value because you needed validation or these values were computed, or something like that. And C# added properties, which is great.
1:18 Python also has really good support for properties. If you want to hide data, that is, like, private data
1:26 within your class, Python doesn't have the keywords around public, private, internal, protected, those kinds of things.
1:34 But, there are several levels of mechanisms in the language to have private data within your classes.
1:41 We also have inheritance. In fact, Python has multiple inheritance which is usually, actually doesn't even appear.
1:47 Sometimes it shows up, sometimes it gets used, but it's actually quite rare that multiple inheritance aspect of
1:54 Python's OOP shows up. But there's a rich inheritance structure, like you have in C#. We can overload operators and we can overload methods
2:04 much like you can change what equals means, or what hash means, or double equals or divide in C#. We can do the same thing with our Python classes.
2:15 We can implement special interfaces. Either this can be deriving from a class and doing something like that.
2:21 Or, there's a whole host of these special methods that are like IDisposable. Remember we talked about with and the compared to the using block.
2:30 There's a set of functions you implement, you effectively implement the usage within that with block. It's not technically an interface, while it's in
2:38 quotes here, but the outcome is the same. You also have abstract methods and abstract classes. If you want to create a base class, you can't create
2:47 an instance of, but you can use it as a base class totally supported in Python. So, you can see, there's a lot here.
2:53 This is not just some little bolt-on thing or it's not that it doesn't exist. OOP in Python is proper object oriented programming.
3:01 We're going to go build some really cool classes and model a particular environment and put them into action.

Talk Python's Mastodon Michael Kennedy's Mastodon