3

Suppose I've two contracts animal and dog, and lets say that:

contract dog is animal {
...
}

Does dog include ALL code of animal, or just the code that it uses?

What if dog uses only a few function of animal? How do I make Solidity skip the other "unused" functions?

2

In the Inheritance part of the Solidity documentation, it states that

When a contract inherits from multiple contracts, only a single contract is created on the blockchain, and the code from all the base contracts is copied into the created contract.

In your case all non-private(public and internal) members and functions of animal contract will be copied into dog contract.

  • What about private functions? – Shuzheng Oct 25 '17 at 5:33
  • Private functions and state variables are only visible for the contract they are defined in and not in derived contracts. – Engin Oct 31 '17 at 6:54
  • 1
    But they are still present in the derived contract? Part of its code? – Shuzheng Oct 31 '17 at 7:39
  • @Shuzheng have you found an answer to this? – Daniel Que Feb 21 '18 at 23:50
2

Dog will include all of the variables and functions within animal.

If you only want to use certain functions you could just break up the base interface into different contracts so that you can use them at your discretion.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.