This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| python:abstraction [2024/12/18 08:45] – [Multiple inheritance] Niels | python:abstraction [2025/01/13 07:30] (current) – [Multiple inheritance] Niels | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ====== Inheritance ====== | ||
| + | Inheritence is very tight coupling. Should be used with care as complex inheritance hierachies can make maintence very complicated. | ||
| + | Try not to go deeper than 1 level of inheritance. | ||
| + | |||
| + | |||
| + | ====== Abstraction ====== | ||
| + | |||
| + | ===== Abstract base classes ===== | ||
| + | Concept similar to interfaces, its a contract for sub classes. | ||
| + | |||
| + | [[https:// | ||
| + | |||
| + | [[https:// | ||
| + | |||
| + | |||
| + | ===== Protocol classes ===== | ||
| + | |||
| + | Defines a interface by defining the properties and functions a class can adhere to. Its more close to duck typing. | ||
| + | Does not rely on inheritance. In runtime the interpreter checks if all the members match. | ||
| + | |||
| + | Protocols allow for finer granularity (interface segregation), | ||
| + | |||
| + | |||
| + | ===== Multiple inheritance ===== | ||
| + | |||
| + | Python supports [[https:// | ||
| + | |||
| + | The multiple inheritance feature is also named mixins as you mix multiple types of classes actually multiple inheritance tree's together. | ||
| + | |||
| + | When using mixins you need to know the implementation details of classes to figure out a resolution order that will work. So the class structure can become complex and hard to work with. | ||
| + | |||
| + | [[https:// | ||
| + | |||
| + | Mixin classes should not have instance variables. | ||
| + | |||
| + | So its powerfull but try to avoid and use with care as it will get complicated. | ||
| + | |||
| + | According to [[https:// | ||