mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #7905 from ethereum/docsChange
[DOCS] Some changes to "abstract contracts".
This commit is contained in:
commit
2b777456a4
@ -6,9 +6,10 @@
|
||||
Abstract Contracts
|
||||
******************
|
||||
|
||||
Contracts need to be marked as abstract when at least one of their functions was not implemented.
|
||||
You can also mark contracts as abstract even though all functions are implemented.
|
||||
This can be done by using the ``abstract`` keyword as shown in the following example. Note, that this contract need to be
|
||||
Contracts need to be marked as abstract when at least one of their functions is not implemented.
|
||||
Contracts may be marked as abstract even though all functions are implemented.
|
||||
|
||||
This can be done by using the ``abstract`` keyword as shown in the following example. Note that this contract needs to be
|
||||
defined as abstract, because the function ``utterance()`` was defined, but no implementation was
|
||||
provided (no implementation body ``{ }`` was given).::
|
||||
|
||||
@ -31,18 +32,23 @@ all defined functions. The usage of an abstract contract as a base class is show
|
||||
function utterance() public override returns (bytes32) { return "miaow"; }
|
||||
}
|
||||
|
||||
If a contract inherits from an abstract contract and does not implement all non-implemented functions by overriding, it needs to be marked as abstract as well.
|
||||
If a contract inherits from an abstract contract and does not implement all non-implemented
|
||||
functions by overriding, it needs to be marked as abstract as well.
|
||||
|
||||
Note that a function without implementation is different from a :ref:`Function Type <function_types>` even though their syntax looks very similar.
|
||||
Note that a function without implementation is different from
|
||||
a :ref:`Function Type <function_types>` even though their syntax looks very similar.
|
||||
|
||||
Example of function without implementation (a function declaration)::
|
||||
|
||||
function foo(address) external returns (address);
|
||||
|
||||
Example of a Function Type (a variable declaration, where the variable is of type ``function``)::
|
||||
Example of a declaration of a variable whose type is a function type::
|
||||
|
||||
function(address) external returns (address) foo;
|
||||
|
||||
Abstract contracts decouple the definition of a contract from its implementation providing better extensibility and self-documentation and
|
||||
Abstract contracts decouple the definition of a contract from its
|
||||
implementation providing better extensibility and self-documentation and
|
||||
facilitating patterns like the `Template method <https://en.wikipedia.org/wiki/Template_method_pattern>`_ and removing code duplication.
|
||||
Abstract contracts are useful in the same way that defining methods in an interface is useful. It is a way for the designer of the abstract contract to say "any child of mine must implement this method".
|
||||
Abstract contracts are useful in the same way that defining methods
|
||||
in an interface is useful. It is a way for the designer of the
|
||||
abstract contract to say "any child of mine must implement this method".
|
||||
|
Loading…
Reference in New Issue
Block a user