Solidity Object-Oriented Features: Inheritance, Interfaces, Libraries, Abstract Contracts and OpenZeppelin

Blockchain Developer 55 min min read Updated: Nov 17, 2026 Intermediate
Solidity Object-Oriented Features: Inheritance, Interfaces, Libraries, Abstract Contracts and OpenZeppelin
Intermediate Topic 4 of 4

Inheritance

solidity contract Animal { function sound() public pure virtual returns (string memory) { return "..."; } } contract Dog is Animal { function sound() public pure override returns (string memory) { return "Woof"; } }
  • is means inherits
  • virtual allows a function to be changed, override changes it
  • Solidity supports multiple inheritance. Order matters, from general to specific

Abstract Contracts and Interfaces

Abstract contractInterface
Has implemented functionsCan haveNo
State variablesAllowedNot allowed
UseShared base with some missing partsDescribes what a contract offers so others can call it
solidity interface IToken { function balanceOf(address who) external view returns (uint256); function transfer(address to, uint256 amount) external returns (bool); }

Calling Another Contract

solidity contract Reader { function tokenBalance(address token, address user) public view returns (uint256) { return IToken(token).balanceOf(user); } }

Libraries

A library holds reusable functions. Use it with using For to extend types, for example safe math helpers or array tools.

OpenZeppelin

  • A widely used library of audited, tested contracts: tokens, access control, security tools
  • Do not write your own ERC-20 or ownership logic from scratch for production. Reuse OpenZeppelin
solidity import "@openzeppelin/contracts/access/Ownable.sol"; contract Vault is Ownable { uint256 public fee; constructor() Ownable(msg.sender) {} function setFee(uint256 f) external onlyOwner { fee = f; } }
Version note OpenZeppelin v5 requires passing the initial owner to Ownable(...). Older tutorials omit it.

Practice

  1. Create a base contract Shape and child Square that overrides area()
  2. What is the difference between an interface and an abstract contract?
  3. Why prefer OpenZeppelin over custom code?

Conclusion

Inheritance, interfaces and libraries organize and reuse code. OpenZeppelin gives audited building blocks so you do not reinvent security-critical parts.

Quick Summary: inheritance; abstract vs interface; calling; libraries; OpenZeppelin.

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators