Ethereum: If there are two overriden functions which one is called

Ethereum: ignoring features in separate contracts

The Ethereum blockchain platform is above Solidity, a programming language used to create smart contracts. Smart contracts are self -executing contracts with the terms of the contract written directly in the ranks of the code. To achieve this, developers use functions and interactions that allow them to ignore or change their existing behavior.

Usually the Ethereum project develops several contracts to perform different tasks. For example, a decentralized financial (DEFI) application could be a system of management of lending protocols, yields and stable rules. In order to make the application more efficient and scalable, developers create separate contracts that can interact with each other.

Problem: Virtual Functions

There is a common challenge in the functions of the essentials. The issue lies in the form of virtual functions. The virtual function is a special type of contract that determines a set of certain methods (functions) without specifying them. These features can be ignored by other contracts.

However, if multiple contracts determine the same virtual function, it creates inconsistencies and difficulties in maintaining the integrity of the project. Here things are getting complicated.

Solution: Separate contracts

To solve this problem, developers create separate contracts that ignore virtual function. There are two main approaches:

  • Using a separate contract : One approach is to create a new contract that simply delegates execution for the original contract function. For example:

`SOLIDITY

FOOD FOO {

Function FOO () Publicly Payable {

// Introduction

}

}

A contract bar {

using FOO {FOO as FOOFUNCTION};

Function overridefoo () Public Return (Bool) {

return FOOFUNCTION ();

}

FOOFUNCTION Function () Social Payable {

// Introduction

}

}

`

In this example, the “bar” agreement ignores the “FOO” contract function, “Foo (), callingFOOFUNCTION ().

  • Using a common storage mechanism

    Ethereum: If there are two overriden functions which one is called

    : Another approach is to use a common storage mechanism, such as storage world or Web3 storage to save data that must enter into multiple contracts. For example:

SOLIDITY

FOOD FOO {

byte public dishes;

Function Setfoodata (byte memory _data) publicly pay {

Foodata = _Data;

}

Function GetFoodata () Public View Returns (byte memory) {

return food;

}

}

A contract bar {

FOO storage Fooinstance;

Function ignoring (byte memory _data) public {

Fooinstance.foodata = _Data;

}

Function GetFoodata () Public View Returns (byte memory) {

return fooinstance.getfoodata ();

}

}

`

In this example, the “BAR” agreement holds data on the instance of the shared storage. The function “OverRidefoodata ()” Updates the saved data, ignoring the original `Foodata () function.

Best Practice

Follow the functions ignored in separate contracts, follow this best practice:

  • Use consistent naming Convention Contracts and Functions.

  • Clearly document the implementation information, including any customized logic or reasoning behind each ignorance.

  • Carefully check to make sure that ignoring is correct and works as expected.

  • Consider using a common storage mechanism such as Web3 storage or storage worlds to save data that must have access to multiple contracts.

Conclusion

Shadow features require careful planning and execution. Understanding the challenges of virtual functions and introducing individual contracts can create more efficient and customizable smart contracts.

Ethereum Solar

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top