Chapter 7. Generalizing functionality with abstract contracts and interfaces

 

This chapter covers

  • Generalizing contracts by making them abstract
  • Improving contract extensibility through interfaces
  • A summary of Solidity object-oriented features
  • Improving maintainability of utility code using libraries

The previous chapter introduced SimpleCrowdsale, which presented an example of a multicontract decentralized application, with a crowdsale management contract (SimpleCrowdsale) interacting with a token contract (ReleasableSimpleCoin).

You started to extend the functionality of SimpleCrowdsale by adding a new, more complex pricing strategy, and took advantage of contract inheritance to do so. You further extended the functionality by implementing pausability and destructibility as separate contracts and composing them into SimpleCrowdsale through multiple inheritance.

In this chapter, you’ll keep extending SimpleCrowdsale’s functionality by using other object-oriented features, such as abstract contracts and interfaces. I’ll show you how an abstract contract can help you generalize a contract while avoiding code duplication. I’ll also demonstrate how interfaces can add flexibility to the design of your contract so you can choose to plug in one of many possible implementations of a specific aspect of the contract functionality.

7.1. Making a contract abstract

7.2. Allowing multiple contract implementations with interfaces

7.3. Real-world crowdsale contracts

7.4. Recap of Solidity’s object-oriented features

7.5. Libraries

7.6. Making SimpleCoin ERC20 compliant

Summary

sitemap