Using Interfaces & Inheritance with Solidity

Using Interfaces & Inheritance with Solidity

There is a lot of information out there on #Blockchain but not very much on #Solidity the programming language used to create Smart Contracts for Blockchain. My background is largely Object Oriented Development and I like to make heavy use of Interfaces when I build applications. I wanted to understand how to do this with Solidity and share the process here.

It turns out that this isn't really all that hard. Since Solidity is Javascript based and object oriented its fairly straight forward. The below code shows a StatementOfWork Solidity contract that pulls in a single function from an iStateMachine interface. The first image defines the interface.

The second image is the StatementOfWork contract.

You can clearly see that on line 28 we are able to implement our interface function thus enforcing our interface contract. The only thing you need is the import statement on line 2 (import "./iStateMachine.sol";) and the contract definition on line 5 (contract StatementOfWork is iStateMachine). The important part is the 'is iStateMachine".

Now inheritance works the exact same way. You just use the Contract keyword as opposed to Interface. I am using Visual Studio Code on a Mac for this. Super light weight and very simple.

Ref: https://solidity.readthedocs.io/en/develop/common-patterns.html#state-machine

要查看或添加评论,请登录

Dr. Joe Shepherd的更多文章

  • Career Success Framework

    Career Success Framework

    Dedicating substantial time to mentorship has allowed me to share my invaluable insights into achieving success and…

    3 条评论
  • The Fourth Industrial Revolution and the Future of Work

    The Fourth Industrial Revolution and the Future of Work

    Influencing Factors (Social, Technological, Ethical) Society, and the world we have come to know it, have undergone…

    4 条评论
  • Corporate Social Responsibility's Impact on Corporate Branding

    Corporate Social Responsibility's Impact on Corporate Branding

    Consumers look to find deeper meaning in everything they do (Vallaster et al., 2012).

  • The Misapplication of Common Marketing Metrics

    The Misapplication of Common Marketing Metrics

    Introduction To prove their worth in the digital age marketing departments, need to consider numerous factors…

  • When Do You Need a Fractional CTO

    When Do You Need a Fractional CTO

    So, you're in charge of technology at your company and the board has just dropped a huge initiative on your plate…

    2 条评论
  • Are you Locked into your Job Description?

    Are you Locked into your Job Description?

    Not all talent is created equally, but the search for all talent begins the same way. Companies looking to fill a role…

    11 条评论
  • Blockchain DAPP Reference Architecture

    Blockchain DAPP Reference Architecture

    When I first started learning about blockchain (BC) development I took all my normal steps to increase my skills. I…

    9 条评论
  • What People Really See in Your Profile

    What People Really See in Your Profile

    I have hired a lot of people in my career. I’ve looked at more resumes and conducted more interviews than I could…

    19 条评论
  • My Donation Went Towards What!?

    My Donation Went Towards What!?

    As rain continues to hammer Houston Texas, people and nations everywhere are opening their hearts and their wallets to…

    7 条评论
  • There has to be a Better Way to Launch...

    There has to be a Better Way to Launch...

    Recently my team and I were responsible for the launch of several new product lines in the streaming media space…

社区洞察

其他会员也浏览了