Inheritance Reading Assignment

Hi @seybastiens,

Q1

That’s correct :white_check_mark:

But this part isn’t … "“the contract that is derived” is the derived contract (child contract).
But, I can see from your answer to Q3 that you already know this, so I think this may just be a slight confusion over how the verb “derive” and the adjective “derived” are used in English.

Q2

Correct :white_check_mark: … although I think it’s clearer if we say, “External functions can be inherited too” … instead of derived.

Q3

I think that what you’ve described here is multi-level inheritance

contract A { ... }

contract B is A { ... }
/*  B is a child/derived contract of A (...derived/inherited from A)
    AND   
    B is also a parent/base contract to C
*/ 
contract C is B { ... }

Hierarchical inheritance is where more than one (multiple) child contracts are derived from the same, single parent contract.

contract A { ... }
contract B is A { ... } 
contract C is A { ... }
contract D is A { ... }

The opposite of hierarchical inheritance is multiple inheritance, which is where more than one (multiple) parent contracts are inherited by the same, single child contract.

contract A { ... }
contract B { ... }
contract C { ... }
contract D is A, B, C { ... }

Let me know if you have any questions :slight_smile:

1 Like

Yes, it was a confusion for Q1. By “the contract that is derived” I meant “the contract that we apply a derivation on”, but it’s more confusing than anything in this case.

Ok I confused multi-level and hierarchical inheritance, thanks.

1 Like

I thought that’s what you probably meant. Don’t worry, I still find it a challenge to describe some of these concepts in an English that makes sense … and English is my native language! :sweat_smile:

1 Like

1. What is the base contract?
The base contract is the contract that is inherited.

2. Which functions are available for derived contracts?
All public and internal scoped functions are available to derived contracts.

3.What is hierarchical inheritance?
Hierarchical inheritance is when multiple contracts inherit from one and the same base contract.

2 Likes

Nice answers @pappas_kellyn :ok_hand:

Just to clarify …

… when the derived contract is compiled, yes … but only the compiled bytecode of the functionality that is inherited from the parent contract is incorporated (which may not be all of it).

When the derived contract is deployed, its single set of compiled bytecode (including what has been incorporated from the parent contract) is deployed at a single Ethereum address (contract address). This single address isn’t really shared because there is only one contract that has actually been deployed.

But you’ve made a really good attempt to describe what’s happening here, and you clearly have a good understanding of this :muscle:

1 Like
  1. What is the base contract? It is parent contract.
  2. Which functions are available for derived contracts? Public, internal and state variable.
  3. What is hierarchical inheritance? Single contract act as a base for multiply derived contracts. E.g.: contract A is derived into contract B and C.
2 Likes
  1. Parent contract
  2. Public and internal functions
  3. An inheritance where a base contract acts as a parents for multiple parents
2 Likes
  1. Base contract = parent contract or the contract that is inherited.

  2. All public and internal functions are available to derived contracts

  3. Hierachical inheritance = a slingle contract acts as a base contract for multiple derived contracts.

1 Like

Good answers @martina :ok_hand:

Just to clarify …

As you say, functions in the base contract with public and internal visibility are available to be called from within the derived contract(s). This is also the case for state variables declared in the base contract i.e. those with public and internal visibility are available for the derived contract(s), but not those with private visibility.

Yes … hierarchical inheritance is where the same, single base contract is inherited by more than one (multiple) derived contracts … The base contract isn’t doing any multiplying :wink:

Hi @stanmation,

Q1 & Q2 :ok_hand:


Q3 What is hierarchical inheritance?

Hierarchical inheritance is where the same, single base/parent contract is inherited by more than one (multiple) derived/child contracts.

  1. What is the base contract?

Contract which has children contracts.

  1. Which functions are available for derived contracts?

All public and internal functions are available for child contracts.

  1. What is hierarchical inheritance?

When parent contract derived into the multiple child contacts.

1 Like

Nice answers @xenmayer :ok_hand:

Just to clarify …

Yes … and a base contract can have just one, or multiple child contracts.


Yes … when the same, single parent contract is inherited by more than one (multiple) child contracts.

1 Like

Thank you for clarification @jon_m :pray:

2 Likes

Thanks for the correction, Jon :slight_smile:

1 Like
  1. The base contract is a parent contract that is inherited from.
  2. Derived contracts can use all public and internal scoped functions of the base contract.
  3. Multiple contracts derived from a base contract.
1 Like
  1. What is the base contract?
    It’s the inherited parent contract .

  2. Which functions are available for derived contracts?
    Public and internal scoped functions

  3. What is hierarchical inheritance?
    A single contract is a base contract for multiple derived contracts.

1 Like
  1. What is the base contract?
    [Ans] It is the contract whose properties - variables & functions, can be inherited by any other contract(child or derived contract). This is to facilitate code-reusability so that reusable pieces can be put together in contracts that other contracts can inherit and reuse instead of creating their own
  2. Which functions are available for derived contracts?
    [Ans] Functions that have visibility type as Public & Internal
  3. What is hierarchical inheritance?
    [Ans] These are inheritance where same base contract gets inherited by multiple child contracts
1 Like
  1. What is the base contract?
  • The contract has a parent known as the derived class and the parent contract is known as a base contract
  1. Which functions are available for derived contracts?
  • All public and internal scoped
    functions and state variables are available to derived contracts.
  1. What is hierarchical inheritance?
  • Hierarchical inheritance is similar to simple inheritance. Only that a single contract acts as a base contract for multiple derived contracts.
1 Like

1 - A base contract is a contract from which others inherit from.

2 - Derived contracts have access to public and internal functions from the parent contract.

3 - Hierarchical inheritance is similar to simple inheritance, however in this particular case, a single contract serves as base contract for multiple derived contracts.

1 Like
  1. Its the parent contract also known as base contract, because child contracts inherits from the parent contract.
  2. All public and internal functions and state variables are available to child contracts.
  3. single contract acts as a base contract for multiple derived contracts.
1 Like