Ev Objects and Multiple Inheritance: How, When, What?

76 views
Skip to first unread message

Tristano Ajmone

unread,
Apr 6, 2015, 11:31:13 AM4/6/15
to eve...@googlegroups.com
Hi everybody! I wanted to ask about multiple inheritance for Evennia typeclassed objects...

Is it possible / useful / advised / tricky?

I haven't so far come across it in the Wiki or in the contrib examples (maybe I just missed it), apart from the prototypes.py relating to @SPAWN.

Let's say I create a typeclassed object that defines a kind of container, and another that defines a supporter (ie: things can be put on top of it, like a table). Then, could I just create a new object which inherits from both, so that I have an object that can both contain other objects and have them on top of it?

This case-example is just to illustrate the nature of my question. I have no idea yet how similar/different are Evennia-typeclassed objects from ordinary Python classes/objects; so I'm basically asking for some eye-opening on the subject.

What is clear to me is that multiple inheritance could provide some cool features to objects creations. But then ... there could also be some pitfalls and conflicts since Evennia objects have some specific features like Cmdsets, locks, ecc.

Thanks

Tristano 

Griatch Art

unread,
Apr 6, 2015, 12:24:24 PM4/6/15
to eve...@googlegroups.com
Typeclasses are inherited like Python classes, so you can use multiple inheritance if you want (the only real difference is that each class must be globally unique, as discussed in the Typeclass documentation.)

A class will overload its parents from left-to-right in a multiple inheritance situation. So adding multiple cmdsets works if you use super() (and add cmdset both in parent and in child. With multiple inheritance you can mix custom methods from the different parents together into a hybrid child class.

So overall it's possible and sometimes it can be really useful. Doing it as a principle might not always be very readable though and can potentially be hard to debug if you are not very sure about just how the inheritance works. Do it if you think you can avoid a lot of doubly-written code, but sometimes it can be clearer to just make a base object with a little more functionality (to make it useful in many different roles). It depends on your design.
.
Griatch

Tristano Ajmone

unread,
Apr 6, 2015, 7:54:34 PM4/6/15
to eve...@googlegroups.com
Thanks, that was very useful. Yes, I guess readability can be an issue, especially if working in team---so, good in-code comments seem more required than ever.
I'll look deeper into it. Maybe creating some base-classes with the sole purpose of being inherited this way (and not used in their base form) could in effect avoid code redundancy.

Reply all
Reply to author
Forward
0 new messages