C3 linearization

From Wikipedia, the free encyclopedia

"In object-oriented systems with multiple inheritance, some mechanism must be used for resolving conflicts when inheriting different definitions of the same property from multiple superclasses."[1] C3 superclass linearization is an algorithm used primarily to obtain the order in which methods should be inherited in the presence of multiple inheritance. In other words, the output of C3 superclass linearization is a deterministic Method Resolution Order (MRO).

C3 superclass linearization is called C3 because it "is consistent with three properties":[1]

  • a consistent extended precedence graph,
  • preservation of local precedence order, and
  • fitting a monotonicity criterion.

It was first published at the 1996 OOPSLA conference, in a paper entitled "A Monotonic Superclass Linearization for Dylan".[1] It was adapted to the Open Dylan implementation in January 2012[2] following an enhancement proposal.[3] It has been chosen as the default algorithm for method resolution in Python 2.3 (and newer),[4][5] Raku,[6] Parrot,[7] Solidity, and PGF/TikZ's Object-Oriented Programming module.[8] It is also available as an alternative, non-default MRO in the core of Perl 5 starting with version 5.10.0.[9] An extension implementation for earlier versions of Perl 5 named Class::C3 exists on CPAN.[10]

Python's Guido van Rossum summarizes C3 superclass linearization thus:[11]

Basically, the idea behind C3 is that if you write down all of the ordering rules imposed by inheritance relationships in a complex class hierarchy, the algorithm will determine a monotonic ordering of the classes that satisfies all of them. If such an ordering can not be determined, the algorithm will fail.

Oops something went wrong: