Reading the docs it says to "add semantics to a function in a declarative ways"
Can I understand it as an "interface" in Java?
Reading the docs it says to "add semantics to a function in a declarative ways"
Can I understand it as an "interface" in Java?
It's just a standard to secure that a certain property is met when somebody calls a particular function.
You can make your own modifier :)
Example 1:
modifier owner() {
if (msg.sender != owner) {
throw;
}
_; // continue executing rest of method body
}
doSomething() isOwner {
// will first check if caller is owner
// code
}
Example 2:
uint256 thisNumber = 4;
modifier HigherThan2(uint256 _x) {
if (_x < 2) {
throw;
}
_; // continue executing rest of method body
}
doMathStuff() HigherThan2(thisNumber) {
// will check if thisNumber is higher than 2
// then, more code
}
On the other hand, you may use predefined modifiers, such as payable.
function ThisSuperICO() payable {
require (msg.value > 0);
// more code
}
Basically is a standard to handle conditions, throwing the call when these conditions are not met.
Hope this helps!
Cheers.
Modifier is a piece of code which consist some validation kind of rules or logic defined by the developer. This piece of code is for the reusability purpose. It is pass in while defining the function in solidity, the purpose of it is to do some validation before running that respective function, now if the validation is failed then the respective function doesn't execute.
Analogy with node.js/express-framework:- Think of it as middleware function.
Analogy with html form validation function:- When submit is triggered with validation function call and if validation fails then the submit is aborted.