Revised
In the code above Foo.a()
is described as an abstract interface (takes one uint
in, is public
(default) and returns nothing) but the actual workings are not defined - there is no {}
block.
contract FooInterface{
function a(uint _amount) public pure returns(uint amount);
}
Foo
could be more explicitly named FooInterface
to avoid confusion with the actual Foo
that implements the function. This is all rather pointless unless there is such thing, so let's suppose it's there with this contrived example.
contract Foo is FooInterface {
function a(uint _amount) public pure returns(uint amount) {
return _amount;
}
}
You don't deploy the FooInterface
, but you deploy a Foo
. Such is implied by the constructor
for Bar
which is asking for actual address of Foo
.
contract Bar {
Foo foo;
function Bar(address _foo) public {
foo = Foo(_foo);
}
function testFoo(uint amount) public view returns(uint number) {
return (foo.a(amount));
}
}
Once Bar is deployed and properly bound to Foo
by the address passed to the constructor, then the testFoo()
function will. It's a contrived example that passes the input to Foo
and returns it to Bar
which returns it to the user.
contract FooInterface{
function a(uint _amount) public pure returns(uint amount);
}
contract Foo is FooInterface {
function a(uint _amount) public pure returns(uint amount) {
return _amount;
}
}
contract Bar {
Foo foo;
function Bar(address _foo) public {
foo = Foo(_foo);
}
function testFoo(uint amount) public view returns(uint number) {
return (foo.a(amount));
}
}
Hope it helps.