250x250
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- graphQL
- solidity
- typeScript
- JavaScript
- Redux
- useState
- bitcoin
- 기준
- evm
- tailwindcss
- middleware
- built in object
- 삶
- Props
- node.js
- CSS
- express.js
- concept
- CLASS
- SSR
- blockchain
- error
- hardhat
- HTML
- nextJS
- API
- Interface
- REACT
- web
- Ethereum
Archives
- Today
- Total
ReasonJun
Solidity : Difference between 'abstract' and 'interface' 본문
Blockchain/Solidity
Solidity : Difference between 'abstract' and 'interface'
ReasonJun 2023. 10. 17. 15:08728x90
Abstract contracts and interfaces are both powerful features of Solidity that can be used to improve the quality, flexibility, and readability of your code. However, there are some key differences between the two.
Abstract contracts
- Abstract contracts are contracts that cannot be deployed by themselves. They must be inherited by other contracts.
- Abstract contracts are used to define the common functionality of a group of related contracts.
- Abstract contracts can contain function declarations, as well as state variables and other code.
- Abstract contracts can be used to implement a variety of design patterns, such as the template method pattern and the strategy pattern.
Interfaces
- Interfaces are contracts that can only contain function declarations.
- Interfaces are used to define the common functionality of a group of related contracts.
- Interfaces cannot contain state variables or other code.
- Interfaces are used to create libraries of reusable functionality and to define the requirements for contracts that you want to interact with.
Here is a table that summarizes the key differences between abstract contracts and interfaces:
Feature | Abstract contract | Interface |
Can be deployed? | No | No |
Must be inherited? | Yes | No |
Can contain state variables? | Yes | No |
Can contain other code? | Yes | No |
When to use abstract contracts
- Use abstract contracts to define the common functionality of a group of related contracts.
- Use abstract contracts to implement design patterns.
When to use interfaces
- Use interfaces to define the requirements for contracts that you want to interact with.
- Use interfaces to create libraries of reusable functionality.
728x90
'Blockchain > Solidity' 카테고리의 다른 글
Solidity : encapsulation & hiding in OOP (0) | 2023.10.17 |
---|---|
Solidity : class / object / method (object-oriented programming language) (0) | 2023.10.17 |
Solidity : interface (0) | 2023.10.17 |
Solidity : abstract (0) | 2023.10.17 |
Solidity : Overriding (virtual / override / super) (0) | 2023.10.17 |
Comments