2

The case I'm dealing with is a contract which should serve as a Data Abstraction Layer.

So ideally, it should provide only getter functions and setter functions.

For example, my interface is:

pragma solidity 0.4.25;

interface IDataAbstractionLayer {
    function getX(uint key) external view returns (uint);
    function getY(uint key) external view returns (uint);
    function getZ(uint key) external view returns (uint);
}

And my contract is:

pragma solidity 0.4.25;

import "./IDataAbstractionLayer.sol";
import "openzeppelin-solidity/contracts/ownership/Ownable.sol";

contract DataAbstractionLayer is IDataAbstractionLayer, Ownable {
    struct Record {
        uint256 x;
        uint256 y;
        uint256 z;
    }

    mapping(address => Record) public records;

    function getX(uint key) external view returns (uint) {return records[key].x;}
    function getY(uint key) external view returns (uint) {return records[key].y;}
    function getZ(uint key) external view returns (uint) {return records[key].z;}

    function set(uint key, uint x, uint y, uint z) external onlyOwner {
        records[key] = Record({x: x, y: y, z: z});
    }
}

The other contracts in my system know this contract only by its interface (i.e., they interact with it only in order to obtain an attribute of a record).

However, since the Solidity compiler adds an implicit getter function for each public variable, this contract also implements the following function:

function records(uint key) external view returns (uint, uint, uint) {
    return (records[key].x, records[key].y, records[key].z);}

So I'm wondering - in the future, if I ever decide that I want to implement and deploy a contract which calls this function, will I be able to simply declare it in the IDataAbstractionLayer interface and then use it in that contract (which will of course know the address of the (already-deployed) DataAbstractionLayer contract)?

Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.