- What is the base contract?
It is the contract all following contracts are derived from - Which functions are available for derived contracts?
Functions from the parent contract and depending on the inheritance also functions from other child contracts. - What is hierarchical inheritance?
A singel contract acts as parent for multiple derived contracts.
Nice answers @Markus_Bielaszka
Just one comment …
Maybe it’s just the way you’ve worded it, but I just want to check what you mean here…
The functions which are available for derived contracts (to call internally) are …
- the public and/or internal functions defined in its parent/base contract;
- any public and/or internal functions inherited by the base/parent contract from its own parent/base contract (the derived contract’s “grandparent”); and
- public, private and internal functions (i.e. all except external functions) defined within the derived contract itself.
It’s normally the derived contract that we deploy, not the base contract. In this case, the following functions can be called either …
- EXTERNALLY (i) public or external functions defined in the derived contract itself; (ii) public functions which have been inherited; and (iii) external functions defined in the base contract(s);
- INTERNALLY from within the derived contract: (i) private, internal or public functions defined in the derived contract itself; and (ii) public or internal functions which have been inherited.
This is kind of the opposite of what you’ve described… but it may actually be what you mean.
Just let me know if you have any questions
Nice answers @Jeremy_Anonymous
A couple of comments …
Q1 What is the base contract?
Just to be clear … a base contract is any parent contract that is inherited by a derived contract. Within an inheritance structure there can be more than one base contract e.g.
// Multi-level inheritance structure
contract A { ... }
contract B is A { ... }
contract C is B { ... }
In this multi-level inheritance structure:
C is a derived contract
A is a base contract… but not the only base contract …
B is both a derived contract (of A), and a base contract (to C)
Basically…
base contract = parent contract
derived contract = child contract
They are just alternative terms for the same thing.
Q3 What is hierarchical inheritance?
Yes … and more specifically, it is where multiple (more than one) child contracts all inherit from the same, single parent contract (but not from each other) e.g.
// Hierarchical inheritance structure
contract A { ... }
contract B is A { ... }
contract C is A { ... }
Let me know if you have any questions
Hi @PaulS96,
Q3
Just to be clear … a base contract is any parent contract that is inherited by a derived contract. Within an inheritance structure there can be more than one base contract e.g.
// Multi-level inheritance structure
contract A { ... }
contract B is A { ... }
contract C is B { ... }
In this multi-level inheritance structure:
C is a derived contract
A is a base contract… but not the only base contract …
B is both a derived contract (of A), and a base contract (to C)
Basically…
base contract = parent contract
derived contract = child contract
They are just alternative terms for the same thing.
Yes, but not all functions are inherited … those with public or internal visibility are available for derived contracts. But functions with private or external visibility are not inherited.
Let me know if anything is unclear, or if you have any questions.
Hey Jon,
What you said makes sense, now that you made me think about it, I can see that what I wrote is wrong and that it doesn’t make any sense. I think I confused myself when I was trying to correctly word it.
Thanks a lot for your comment, always learning a lot from your feedback!
Glad my comment was helpful… It can be really difficult to put what we want to say about some of these concepts into words, especially if we try to explain things in more detail, so I totally understand … but don’t let that stop you from attempting a more detailed explanation, because even if the words aren’t quite right, it can be an excellent way to make you think about things more deeply and to eventually gain a deeper understanding
Corrected my answer:
public and internal functions contract are available for derived contracts.
Anyone can interact with the public functions, it can be called by the same contract and contracts inherit from the parent contract.
internal functions can only be called by other functions in the same contract(similar to private) and functions in contracts that inherit from parent contracts.
Correct
Your description for internal functions also applies to public functions AND, as you say, anyone can interact with public functions, and so they can also be called externally (both those that are defined in the derived contract, and those that are inherited from parent contracts).
Yes I see, I was thinking of that, but didn’t think about writing it, but it makes sense.
I was also thinking that it could be called externally, but I wasn’t sure if it was correct so I didn’t add that, but it makes sense that they could also be called externally.
Thank you for making it clearer for me! I appreciate it a lot
- A base contract is the parent contract.
- public and internal scoped functions
- Its an inheritance where a single contract works as a base contract for many different derived contracts.
- The base contract is the parent contract from which other contracts can inherit.
- The functions implemented in the parent contract.
- It is when one base contract serves as parent to multiple child contracts.
Hi @belinox,
Q1 & Q3
Q2 Which functions are available for derived contracts
Yes … but not necessarily all of them … Functions defined in the parent contract with public or internal visibility are available to be called from within the derived contract.
Those with private or external visibility aren’t available to be called from within the derived contract; but when the derived contract is deployed, external functions defined in the parent contract can be called externally.
Let me know if anything is unclear, or if you have any questions.
-
What is the base contract?
parent contract is known as a base contract -
Which functions are available for derived contracts?
all public and internal scoped
functions and state variables are available to derived contracts. -
What is hierarchical inheritance?
Its when a single contract acts as a base contract for multiple derived contracts.
1. What is the base contract? The parent contract
2. Which functions are available for derived contracts? Any functions defined in the base contract from which the derived contract is derived from
3. What is hierarchical inheritance? It’s when a single base contract is the basis for many derived contracts.
- A base contract is the inherited contract by a derived contract (which inherits from it.
- All public and internal scoped functions and state variables are available to derived contracts.
- When a contract is the base contract of multiple derived contracts.
Hi @obikodi,
Q1 & Q3
Not any functions defined in the base contract… Those with public or internal visibility are available to be called from within the derived contract, but those with private or external visibility are not. However, when the derived contract is deployed, external functions defined in the base contract can be called externally.
Yes … whenever a single base contract has more than one derived contract.
Let me know if anything is unclear, or if you have any questions.
Oh Hey Jon thank you so much for the reply. I honestly thought nobody looked at these assignment submissions so i kinda haven’t been doing them, only on the odd occasion. Guess i’ll start doing them from now on lol and also thank you for taking the time to respond, it is helpful
Hey @obikodi,
Yes, assignment submissions are reviewed In this course, I try to give as much constructive feedback as possible, as it’s important to get a good solid foundation before moving on to more advanced Solidity smart-contract programming. It’s important to get as much practice with the code as possible, so I really do encourage you spend time on the assignments.
Glad you found the feedback helpful
- What is the base contract? The parent contract.
- Which functions are available for derived contracts? The ones where the parent contract allows children to use them via correct encapsuation) public or internal should be allowed by parent for child to call.
- What is hierarchical inheritance? When multiple children derive from the same parent(base contract)