jargon

Comparison

Diamond problemvsMixin

Diamond problem

two parents both define the method and the language has to pick one, and which one is a rule you had to look up.

The ambiguity when a class inherits the same member along two different paths from a shared ancestor. It is the standard reason a language bans multiple inheritance of implementation and offers interfaces or mixins with an explicit resolution order instead. Knowing the term matters mostly for reading a linearisation error message and for the interview question about why one language allows it and another does not.

Full entry →

Mixin

the class picks up three methods from somewhere that is not its parent, and finding where they came from takes a search.

A bundle of behaviour designed to be mixed into a class rather than instantiated on its own, giving reuse across an inheritance tree without a common ancestor. It solves the problem that single inheritance only has one slot, and creates the problem that the set of methods on a class is no longer readable from its declaration. Languages disagree wildly on the details — traits, modules, protocol extensions — but the trade is the same everywhere.

Full entry →

Related comparisons