Inheritance Reading Assignment

  1. The base contract is the parent or “inherited” contract.

  2. Any public or internal-scoped functions (or state variables) in the parent contract are available for child or “derived” contracts.

  3. Hierarchical inheritance occurs when a parent contract has two derived/child contracts that are not connected to one another except through the parent code (i.e. - Contract B is A; Contract C is A).

1 Like
  1. It is a parent class (contract) that can be inherited to child contracts
  2. All public and internal scoped functions are available for derived contracts to use
  3. Contract that can be only the one single parent of other child contracts
1 Like

Hey guys, I thought interface is an abstraction. But looks like there are differences in Solidity. Honestly I didint understand the differences between those two when i was going over blog that Fillip shared :frowning:

1 Like

Nice answers @Acex13 :ok_hand:

Yes… and there can also be more than 2 derived contracts (effectively siblings) in this type of inheritance structure.

Nice answers @Anvar_Xadja :ok_hand:

Effectively, yes… hierarchical inheritance is where the same, single parent contract is inherited by more than one (multiple) child contracts.

Hi @Anvar_Xadja,

There are similarities between interfaces and abstract contracts, but also some key differences.

Don’t worry… that part of the article isn’t very clear, and the author has incorrectly used the abstract contracts example for interfaces as well, which makes it even more confusing! :crazy_face:
All functions in an interface can only be declarations without function bodies.

This is a complex area of Solidity, but try the following article, which I think is much clearer on the subject, even though there are probably a few concepts you’ll need to do some further research on. In terms of syntax, both this article and the assignment article are out-of-date now. For example, all function declarations in an interface should now be marked with external visibility. Additionally, Solidity v0.6.0 introduced the keywords abstract , virtual and override. One of the additional restrictions for interfaces, mentioned in the article below, has also changed: from Solidity v0.7.0 interfaces can now inherit other interfaces, whereas before v0.7.0 they couldn’t. As long as you bear these things in mind, I think the article below is still helpful as an introduction to the differences between interfaces and abstract contracts in Solidity. You can find more details about the specifics, and the changes I’ve mentioned, in the Solidity documentation itself (links below the article)… when you’re feeling brave enough :muscle:

https://medium.com/upstate-interactive/solidity-how-to-know-when-to-use-abstract-contracts-vs-interfaces-874cab860c56

Solidity Documentation
v0.6.0
Abstract Contracts   https://docs.soliditylang.org/en/v0.6.0/contracts.html#abstract-contracts
Interfaces        https://docs.soliditylang.org/en/v0.6.0/contracts.html#interfaces
Function Overriding   https://docs.soliditylang.org/en/v0.6.0/contracts.html#index-17
Latest Version
Abstract Contracts   https://docs.soliditylang.org/en/latest/contracts.html#abstract-contracts
Interfaces        https://docs.soliditylang.org/en/latest/contracts.html#interfaces

Have fun! … and let me know if you have any questions :slight_smile:

2 Likes
  1. What is the base contract?

The base contract is another term for the parent contract, which is the first contract in a hierarchal line of inheritance.

  1. Which functions are available for derived contracts?

All public and internal scoped functions and state variables of the parent contract.

  1. What is hierarchical inheritance?

Where a single contract acts as a base contract for multiple derived contracts.

2 Likes
  1. The base contract, also known as the parent contract and is the contract that is inherited when making contract composition.

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

  3. In hierarchical inheritance a single contract acts as a base contract for multiple derived contracts.

2 Likes

1- What is the base contract?

The contract that is inherited (Inheritance is the process of defining multiple contracts that are related to each other through parent-child relationships.) is called the parent contract and the contract that inherits is called the child contract. The parent contract is known as a base contract.

2-Which functions are available for derived contracts?

All public and internal scoped functions, and the state variables are available to derived contracts.

3- What is hierarchical inheritance?

Hierarchical inheritance is similar to simple inheritance. In this one, a single contract acts as a base contract for multiple derived contracts.

2 Likes

Nice answers @Zaqoy :ok_hand:

This is true… however, we can also have an inheritance structure where one of the contracts is both a base contract and a derived contract. For example, consider this multi-level inheritance structure:

contract A { ... }         // parent of B
contract B is A { ... }    // child of A, and parent of C
contract C is B { ... }    // child of B

Let me know if you have any questions :slight_smile:

1 Like

Nice answers @TolgaKmbl :ok_hand:

Just one comment about Q2

Just to be clear, as with functions, not all state variables in the base contract are available to the derived contract:
Public and internal state variables are inherited (i.e. both private functions and private state variables are not inherited).

Let me know if you have any questions :slight_smile:

2 Likes

What is the base contract?

The base contract is the contract that is inherited or better known as the Parent contract.

Which functions are available for derived contracts?

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

What is hierarchical inheritance?

It is a single contract which acts as a base (parent) contract for multiple derived (child) contracts.

2 Likes
  1. What is the base contract? - it is a contact inherited by another contract or a parent contract.
  2. Which functions are available for derived contracts? - all public and internal scope functions and state variables are available for derived contracts.
  3. What is hierarchical inheritance? - a single contract acts as a base for multiple contracts.
2 Likes

Nice answers, and great design! :smiley:

2 Likes
  1. The base contract is the parent of derived contracts
  2. functions and variables that are in the public or internal scope
    3.When a single contract acts as a base contract for multiple derived contracts
2 Likes
  1. What is the base contract?

The Parent smart contract

  1. Which functions are available for derived contracts?

Public and internal

  1. What is hierarchical inheritance?

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

2 Likes

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

2. Which functions are available for derived contracts?
Functions defined with public and internal visibility.

3. What is hierarchical inheritance?
A parent contract is inherited by multiple child contracts.

2 Likes
  1. The base contract is the parent contract that is inherited by the derived or child contract.

  2. The functions that are available to derived contracts are all of the public and internal scoped ones as well as state variables.

  3. Hierarchical inheritance is when a single contract acts as a base for multiple derived contracts.

1 Like

Nice answers @Dustin_Gearhart :ok_hand:

Just to be clear, as with functions, not all state variables in the base contract are available to the derived contract:
Public and internal state variables are inherited (i.e. both private functions and private state variables are not inherited).

Just let me know if you have any questions :slight_smile:

1 Like
  1. The base contract or parent contract is the contract that gets inherited in the child or derived contract.

  2. Public and Internal functions in the parent contract are available to the derived or child contract.

  3. Hierarchical inheritance is when a contract is inherited by multiple child or derived contracts.

1 Like