-
The original contract that is being referenced from.
-
All public and internal scoped functions.
-
A single contract that acts as a base contract for multiple derived contracts.
Good answers @h0h
Just one comment ā¦
Q1ā What is the base contract?
I wouldnāt call the parent/base contract the original contract, as thatās misleading. The main purpose of a parent/base contract is to be inherited, so that when the derived contract is compiled, all of the functionality it inherits from the base/parent contract is incorporated. The result is a single set of bytecode, which is then deployed at a single Ethereum address on the Ethereum blockchain.
Let me know if you have any questions
- Parent Contract
- all of them
- child inherits from parent. single contract is the super set for the derivatives, inheriting the functions.
Hi @diehlca17,
Q1
Q2 Which functions are available for derived contracts?
Noā¦ not all of the functions in the base contract are available. Functions with public
or internal
visibility are available for derived contracts, but not those with private
visibility.
A function in the base contract with external
visibility will be inherited by a derived contract, but only to the extent that, when the derived contract is deployed, this function will be available to call externally e.g. from Remix, a web3 client (such as the front-end interface of a dapp), or from an external (i.e. non-derived) contract. However, unlike public
and internal
functions, an external
function in the base contract is not available to be called from within the derived contract itself.
The only functions which arenāt inherited are those with private
visibility.
Q3 What is hierarchical inheritance?
Hierarchical inheritance is where more than one (multiple) child contracts all/both inherit from the same, single parent contract.
Is that what you mean by this? ā¦
I wouldnāt say that the child contracts are derivatives of a superset (the parent), because that implies that the child contracts only contain elements inherited from the parent. However, the child contracts will have a lot of their own additional functionality, and will only inherit some specific functionality from their parent. And, as Iāve mentioned above, any private functions (and also private state variables) will not be inherited by the child contracts from their parent.
Let me know if you have any questions
- A base contract is the parent contract
- All public and internal scoped functions and state variables are available to derived contracts.
- Where a single contract acts as a base contract for multiple derived contracts.
-
The base contract is the parent contract.
-
The derived contracts inherit everything from its parent or base contract. Therefore all functions that are present and useable in the parent contract is inherited and able to use in the derived contracts.
-
Hierarchal inheritance is when multiple derived contracts inherit from a single base contract. Eventually this forms a web that can be retraced to one source from which the inheritance takes place. This is where the hierarchal comes from as it takes on a form similar to a family tree.
Hi @0xsundown,
Q1
Q3 Excellent answer
Q2 Which functions are available for derived contracts?
Noā¦ not all of the functions in the base contract are available to be called from within the derived contract(s). Functions with public
or internal
visibility are available for derived contracts, but not those with private
or external
visibility.
A function in the base contract with external
visibility will be inherited by a derived contract, but only to the extent that, when the derived contract is deployed, this function will be available to call externally e.g. from Remix, a web3 client (such as the front-end interface of a dapp), or from an external (i.e. non-derived) contract. However, unlike public
and internal
functions, an external
function in the base contract is not available to be called from within the derived contract itself.
The only functions which arenāt inherited are those with private
visibility.
Let me know if you have any questions
Thank you so much for that explanation @jon_m! I see I overlooked the visibility functions. Thank you for the clarification on that!
- Base contract is the parent contract in an inheritance relationship between a parent and a child contract.
- All functions from parent contract with visibility public or internal are available in the derived class.
- Hierarchical inheritance is inheritance in the case of one base contract having two or more derived contracts.
1: The base contract is the parent contract that any other child contract has inheritance from.
2: All public and internal functions are available to derived contracts.
3: Hierarchical inheritance is where one base contract is the base to various one leveled
derived contracts.
Hi Jon
Iāve been away from the course for a bit and am now getting back into it. I noticed your reply to my inheritance post but couldnāt figure out how to edit it so I deleted the post and reposted it without the questions that Iād copied and pasted that had errors.
thanks for the guidance
Douglas
-
What is the base contract?
The contract from which contracts, public functions, state variables, modifiers and events are inherited. -
Which functions are available for derived contracts?
Functions that are āpublicā or āinternalā -
What is hierarchical inheritance?
This is a parent-child structure in which mutiple āchildrenā inherit from the same parent-contract (or base contract)
- What is the base contract?: the parent contract.
- Which functions are available for derived contracts? : Polymorphism
- What is hierarchical inheritance? : It is similar to simple inheritance
Hey Douglas,
No problem! Glad hear youāre getting back into the course
Nice answers @R0bert
Just one comment ā¦
Contracts canāt be inherited from another contract, because contracts donāt contain contracts. The contract itself is inherited.
As well as public
functions, functions with internal
or external
visibility are also inherited. The only functions which arenāt inherited are those with private
visibility.
A function in the base contract with external
visibility will be inherited by a derived contract, but only to the extent that, when the derived contract is deployed, this function will be available to call externally e.g. from Remix, a web3 client (such as the front-end interface of a dapp), or from an external (i.e. non-derived) contract. However, unlike public
and internal
functions, an external
function in the base contract is not available to be called from within the derived contract itself.
Let me know if you have any questions
Hi @jadelaawar,
Q1
No ā¦
The visibility of a function determines whether it is inherited and available to be called from a derived contract.
Functions with public
or internal
visibility are available for derived contracts, but not those with private
or external
visibility.
But this doesnāt actually tell us what hierarchical inheritance is ā¦
Hierarchical inheritance is where more than one child contract inherits from the same, single parent contract e.g.
contract A { ... }
contract B is A { ... }
contract C is A { ... }
Whereas single inheritance is where a single child contract inherits from a single parent contract .
contract A { ... }
contract B is A { ... }
The correct term is single inheritance (not simple inheritance)
Let me know if you have any questions
Thanks for the reply. Itās more clear to me now
- The parent
- Public and internal scoped functions and state variables
- Single contract acts as a base for multiple derived contracts
- What is the base contract?
- it is a contract from contract child Inherits function and variableā¦ - Which functions are available for derived contracts?
- All function ,excluded āprivateā function. - What is hierarchical inheritance?
- when plus contracts child derive from one base contract