portagency.blogg.se

Python oop inheritance
Python oop inheritance













python oop inheritance

If you get enough requests for something new, then you can consider adding it, but first let the clients play with it. Inheritance allows you to create super simple classes, and for your users to modify the classes. You hadn't even considered it, but now you're adding something that makes a whole lot more sense in practice. You may find that almost all of your clients are requesting a feature for the hammer to have one side for pounding nails, and the other side for prying out nails. Instead, you want to just ship the simplest version of your product, and see what clients think. You will want to let clients modify the hammer class if they want a rubber hammer (the equivalent of buying a rubber hammer instead). It can be tempting to implement your ideas, because they sound reasonable to you, but you don't want to do that.

python oop inheritance

You might have various ideas, like maybe having a hammer with two sides to head for various sizes of nails, or maybe some sort of blended head where one side is metal and the other is rubber! This is a minimum viable product (MVP), and should be shipped in this state. Your hammer will have attributes like a handle, and then a metal head of some kind for pounding nails. In my cases, you're creating a tool that people will use. One way to think about it is that you're creating a product that people will use. When creating classes and using Object Oriented Programming, we're usually doing it under the idea that we're making something that either other people will use or our future selves will use. Inheritance is a major form of modularity, but actually also plays roles in scaling and maintainability.

python oop inheritance

In this part of the series, we're going to discuss inheritance. Welcome to part 17 of the intermediate Python programming tutorial series.















Python oop inheritance