Clarified the potential pitfalls with multiple inheritance. Resolve #3791
This commit is contained in:
parent
fafcbf291f
commit
0b92202ae6
1 changed files with 123 additions and 122 deletions
|
|
@ -77,7 +77,8 @@ class EvAdventureMob(LivingMixin, EvadventureNPC):
|
|||
In [evennia/contrib/tutorials/evadventure/characters.py](../../../api/evennia.contrib.tutorials.evadventure.characters.md)
|
||||
is an example of a character class structure.
|
||||
```
|
||||
Above, the `LivingMixin` class cannot work on its own - it just 'patches' the other classes with some extra functionality all living things should be able to do. This is an example of _multiple inheritance_. It's useful to know about, but one should not over-do multiple inheritance since it can also get confusing to follow the code.
|
||||
Above, the `LivingMixin` class cannot work on its own - it just 'patches' the other classes with some extra functionality all living things should be able to do. This is an example of _multiple inheritance_. The order of inheritance matters here - the `LivingMixin` must come _before_ `DefaultCharacter` (or EvAdventureNPC etc) so that its methods are found first when called.Multiple inheritance is a powerful tool in object-oriented programming, and useful to know about. Be careful to over-use it, however. If you have too many mixins it can get hard to follow which method comes from where.
|
||||
|
||||
|
||||
## Living mixin class
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue