-
What is the base contract?
The base contract is essentially the parent contract or the derived class. -
Which functions are available for derived contracts?
Derived contracts can be used as base contracts together in further child classes. -
What is hierarchical inheritance?
Inheritance is the process of defining multiple contracts that are related to each other through parent-child relationships. The contract that is inherited is called the parent contract and the contract that inherits is called the child contract.
- A base contract is a contract from which derived child contracts inherit properties and functions.
- All functions of the base contract: public, private and internal - are available to derived contracts.
- In Hierarchical Inheritance, contracts are derived from a single base contract.
1.)
The contract that is inherited is called the parent contract and the contract that inherits is called the child contract.
Similarly, the contract has a parent known as the derived class and the parent contract is known as a base contract.
2.)
All public and internal scoped functions and state variables are available to derived contracts.
3.)
Hierarchical inheritance is again similar to simple inheritance. Here, however, a single contract acts as a base contract for multiple derived contracts.
- Parent contract.
- All public and internal scoped functions are available in a derived contract.
- A single contract acts as a base contract for multiple derived contracts.
Hi @franzmoro,
Q1
No, not all functions in the base contract are inherited. Public and internal functions are available for derived contracts, but not those with private or external visibility. The same is true for state variables.
Yes — the key here being the fact that there is more than just one derived contract from the single base contract.
What is the base contract?
The base contract or parent contract is from which child contracts are derived from in an inheritance relationship.
Which functions are available for derived contracts?
Functions with public or internal accessibility are available for derived contracts.
What is hierarchical inheritance?
Hierarchical inheritance is when multiple derived contracts inherit from the same base contract.
What is the base contract?
AKA parent contract, therefore all other contracts are derived from the base contract.
Which functions are available for derived contracts?
To create a single contract with inheritance,
What is hierarchical inheritance?
A single contract acts as a base contract for multiple derived contracts.
-
The contract that can be inherited by other derived or child contracts.
-
All functions
-
A type of inheritance where a single contract acts as a base contract for multiple derived ones.
-
What is the base contract?
Base contract is another term for parent contract and the contract that inherits is called the child 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?
Hierarchical inheritance is similar to simple inheritance. Here, however, a single contract acts as a base contract for multiple derived contracts.
There was one thing in this article (https://medium.com/coinmonks/solidity-and-object-oriented-programming-oop-191f8deb8316) I did not understand. At the end of the article the difference between Abstract Contracts
and Interfaces
is explained. However the example code for these two different things looks exactly the same:
pragma solidity ^0.4.19;
contract abstractHelloWorld {
function GetValue() public view returns (uint);
function SetValue(uint _value) public;
function AddNumber(uint _value) public returns (uint) {
return 10;
}
}
contract HelloWorld is abstractHelloWorld{
uint private simpleInteger;
function GetValue() public view returns (uint) {
return simpleInteger;
}
function SetValue(uint _value) public {
simpleInteger = _value;
}
function AddNumber(uint _value) public returns (uint ){
return simpleInteger = _value;
}
}
But I think for Interfaces
this code doesn’t match, because it is stated, that Interfaces
can only contain function declarations.This means that functions in interfaces cannot contain any code. So I guess this is just a “copy-and-paste” error and the author of this article just forgot to delete the code in the fuctions of the interfaces.
- What is the base contract?
The contract that is inherited(also called parent) - Which functions are available for derived contracts?
base contracts - What is hierarchical inheritance?
a single contract acts as a base contract for multiple derived contracts.
- The first contract (parent). The one that gets inherited.
- All public and internal functions and state variables are available.
- A single contract acts as a base contract for multiple derived contracts.
-
The parent contract. The first contract created where other contracts are derived from
-
All public and internal scoped functions and state variables are available to derived contracts.
Function polymorphism refers to declaring multiple functions within the same contract or inheriting
contracts having the same name -
A hierarchal structure that determines which contract is the parent contract and which contracts are the child contracts.
Hello @Ouzo69, hope you are OK.
Now, that article could be as you said, the author forgot to type the correct code, that example is for inheritance, not interfaces.
A interface will require that a contract is already deployed, you will use its address and the contract public or external functions to interact from your contract to that one.
You should not be able to design new logic on a deployed contract, you should only be able to interact with functions that are coded into the interfaced contract, external and public only.
Carlos Z.
- The Base contract is the highest contract in the hierarchy or line of inheritance. It is the parent contract of which the child contracts are derived.
- Derived contract have available to them public and external functions from other contracts, internal functions from any parent contracts, and of course, public, private, and internal functions that are defined in the contract itself.
- Hierarchical inheritance implies that we can have multiple contracts inheriting from a single contract. So, one contract can be the parent for any number of contracts. For example, contracts B and C can inherit from contract A, contracts D and E can inherit from B, F and G inheriting from C, and so on.
Hi @mickymax777,
Q1 & Q3
You’ve misunderstood what Q2 is asking…
It means which functions (as in code) are inherited by derived contracts from their parents (not functions as in job/purpose).
Functions with public
or internal
visibility are available for derived contracts.
HI @alegarap,
Q1 & Q3
No, not all functions in the base contract are inherited. Public and internal functions are available for derived contracts, but not those with private or external visibility. The same is true for state variables and mappings.
Hi @sajede.k,
Q1 & Q3
Yes, but not all functions in the base contract are inherited. Public and internal functions are available for derived contracts, but not those with private or external visibility. The same is true for state variables and mappings.
-
What is the base contract?
R: Base contract = parent contract = inherited contract -
Which functions are available for derived contracts?
R: Polymorphism -
What is hierarchical inheritance?
R: Contract A is derived in both Contract B and Contract C