So, if we have 3 contracts (A, B and C) and we want…
Example 1
- B to inherit from A
- C to inherit from both A and B
… we can code:
contract A {}
contract B is A {}
contract C is B {}
/*
contract C is A, B {}
No need to add A here because C automatically inherits A from B
*/
Is the correct term for this type of contract composition multi-level inheritance?
Example 2
Now let’s say we want both B and C
- to inherit from A (as in Example 1)
- but not from each other (different to Example 1)
In other words, instead of 3 “generations” with C being A’s “grandchild” and B’s child,
we now have just 2 “generations”, with C being A’s child (as well as B).
I assume we would code this as follows:
contract A {}
contract B is A {}
contract C is A {} // only difference to Example 1 where: C is B
Is the correct term for this type of contract composition hierarchical inheritance?
Example 3
Now let’s say we want to keep the same contract composition as in Example 2, but also add an additional contract (contract D) which will inherit from contract A, B and C.
We now have 3 “generations” again, with contract D being A’s “grandchild” and child of both B an C.
For our additional contract D, would we add the following to our Example 2 code?
contract D is B, C {}
/*
contract D is A, B, C {}
No need to add A here because D automatically inherits A from B and C.
Is that correct?
*/
Is the correct term for this type of contract composition multiple inheritance?