Fund:0.012 ETH / $6.94
Question is solved

Multiple Inheritance and Diamond Pattern

1 month ago

How does Solidity deal with the order of multiple inheritances?


The most base like class must come first. To solve the diamond problem in multiple inheritance, Solidity uses a constructor initialization algorithm similar to Python called C3 Linearization to force a specific order in the graph of base classes. For example, B derives from A and C derives from A. Then D derives from both B and A. If B and C overrides a method called foo() in A. Then when D calls foo(), it will either call B or C depending on which one was specified first. If Contract D is B, C, then it will call the foo() in C since it’s the most derived. The inheritance graph looks like this: D -> C -> B -> A. If Contract D is C, B, then it will call the foo() in B and the graph looks like this D -> B -> C -> A.
1 month ago

Your question is successfully refund. You will be redirect in few seconds.