Mixins vs. Traits

Mixins may contain state, (traditional) traits don’t. Mixins use “implicit conflict resolution”, traits use “explicit conflict resolution” Mixins depends on linearization, traits are flattened. Lecture about traits ad 1. In mixins you can define instance variables. Traits do not allow this. The state must be provided by the composing class (=class using the traits) ad … Read more

Are defaults in JDK 8 a form of multiple inheritance in Java?

The answer to the duplicate operation is: To solve multiple inheritance issue a class implementing two interfaces providing a default implementation for the same method name and signature must provide an implementation of the method. [Full Article] My answer to your question is: Yes, it is a form of multiple inheritance, because you can inherit … Read more

python abstractmethod with another baseclass breaks abstract functionality

Surprisingly, the test that prevents instantiating abstract classes happens in object.__new__, rather than anything defined by the abc module itself: static PyObject * object_new(PyTypeObject *type, PyObject *args, PyObject *kwds) { … if (type->tp_flags & Py_TPFLAGS_IS_ABSTRACT) { … PyErr_Format(PyExc_TypeError, “Can’t instantiate abstract class %s ” “with abstract methods %U”, type->tp_name, joined); (Almost?) all built-in types that … Read more

A use for multiple inheritance?

Most uses of full scale Multiple inheritance are for mixins. As an example: class DraggableWindow : Window, Draggable { } class SkinnableWindow : Window, Skinnable { } class DraggableSkinnableWindow : Window, Draggable, Skinnable { } etc… In most cases, it’s best to use multiple inheritance to do strictly interface inheritance. class DraggableWindow : Window, IDraggable … Read more

Virtual tables and memory layout in multiple virtual inheritance

Virtual bases are very different from ordinary bases. Remember that “virtual” means “determined at runtime” — thus the entire base subobject must be determined at runtime. Imagine that you are getting a B & x reference, and you are tasked to find the A::a member. If the inheritance were real, then B has a superclass … Read more