Inheritance Reading Assignment

  1. The original contract that is being referenced from.

  2. All public and internal scoped functions.

  3. A single contract that acts as a base contract for multiple derived contracts.

1 Like

Good answers @h0h :ok_hand:

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 :slight_smile:

  1. Parent Contract
  2. all of them
  3. child inherits from parent. single contract is the super set for the derivatives, inheriting the functions.

Hi @diehlca17,

Q1 :ok_hand:

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 :slight_smile:

  1. A base contract is the parent contract
  2. All public and internal scoped functions and state variables are available to derived contracts.
  3. Where a single contract acts as a base contract for multiple derived contracts.
1 Like
  1. The base contract is the parent contract.

  2. 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.

  3. 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.

1 Like

Hi @0xsundown,

Q1 :ok_hand:

Q3 Excellent answer :muscle:

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 :slight_smile:

2 Likes

Thank you so much for that explanation @jon_m! I see I overlooked the visibility functions. Thank you for the clarification on that!

1 Like
  1. Base contract is the parent contract in an inheritance relationship between a parent and a child contract.
  2. All functions from parent contract with visibility public or internal are available in the derived class.
  3. Hierarchical inheritance is inheritance in the case of one base contract having two or more derived contracts.
1 Like

Great answers @cesc ā€¦ clear, accurate, and very well explained :muscle:

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.

1 Like

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

1 Like
  1. What is the base contract?
    The contract from which contracts, public functions, state variables, modifiers and events are inherited.

  2. Which functions are available for derived contracts?
    Functions that are ā€œpublicā€ or ā€œinternalā€

  3. What is hierarchical inheritance?
    This is a parent-child structure in which mutiple ā€œchildrenā€ inherit from the same parent-contract (or base contract)

1 Like
  1. What is the base contract?: the parent contract.
  2. Which functions are available for derived contracts? : Polymorphism
  3. What is hierarchical inheritance? : It is similar to simple inheritance

Hey Douglas,

No problem! Glad hear youā€™re getting back into the course :slight_smile:

Nice answers @R0bert :ok_hand:

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 :slight_smile:

1 Like

Hi @jadelaawar,

Q1 :ok_hand:


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 :slight_smile:

Thanks for the reply. Itā€™s more clear to me now :slight_smile:

1 Like
  1. The parent
  2. Public and internal scoped functions and state variables
  3. Single contract acts as a base for multiple derived contracts
2 Likes
  1. What is the base contract?
    - it is a contract from contract child Inherits function and variableā€¦
  2. Which functions are available for derived contracts?
    - All function ,excluded ā€œprivateā€ function.
  3. What is hierarchical inheritance?
    • when plus contracts child derive from one base contract
2 Likes