MRO xác định thứ tự Python tìm method trong cây kế thừa, dùng thuật toán C3 Linearization.
Giải quyết diamond problem bằng cách đảm bảo mỗi class chỉ xuất hiện một lần.
python
class A:
def method(self): print("A")
class B(A):
def method(self): super().method(); print("B")
class C(A):
def method(self): super().method(); print("C")
class D(B, C): pass
D().method() # A → C → B (theo MRO)
print(D.__mro__) # D, B, C, A, objectXem MRO: ClassName.__mro__ hoặc ClassName.mro().
MRO defines the order Python searches for methods in the inheritance tree, using C3 Linearization.
Solves the diamond problem by ensuring each class appears only once.
python
class D(B, C): pass
print(D.__mro__) # D → B → C → A → object
D().method() # Calls in MRO order