concept SimpleCrowdsale in category ethereum

This is an excerpt from Manning's book Building Ethereum Dapps: Decentralized applications on the Ethereum blockchain.
As I noted, SimpleCoin and SimpleCrowdsale use the same onlyOwner modifier to restrict access to some operations to only the contract owner. The advantage is that you’re using onlyOwner consistently across the two contracts. The downside is that you had to introduce the owner state variable and implement the onlyOwner modifier in both contracts. Wouldn’t it be nice to place this modifier somewhere so you could then drop it into both SimpleCoin and SimpleCrowdsale without introducing code duplication? Fortunately, you can by encapsulating the ownership state and onlyOwner modifier into a separate contract, called Ownable, as shown in the following listing.
Listing 6.4. Ownable contract extracted from SimpleCrowdsale and SimpleCoin
pragma solidity ^0.4.18; contract Ownable { address public owner; #1 constructor() public { owner = msg.sender; #2 } modifier onlyOwner() { require(msg.sender == owner); #3 _; } }Now you can remove the owner state variable and the onlyOwner() modifier from both SimpleCoin and SimpleCrowdsale and inherit both contracts from Ownable, as shown in the contract diagram in figure 6.3 and in this code:
SimpleCoin is Ownable { ... } SimpleCrowdsale is Ownable { ... } !@%STYLE%@! {"css":"{\"css\": \"font-weight: bold;\"}","target":"[[{\"line\":0,\"ch\":11},{\"line\":0,\"ch\":21}],[{\"line\":4,\"ch\":16},{\"line\":4,\"ch\":26}],[{\"line\":0,\"ch\":11},{\"line\":0,\"ch\":21}],[{\"line\":4,\"ch\":16},{\"line\":4,\"ch\":26}]]"} !@%STYLE%@!
The arrow between SimpleCrowdsale and ReleasableSimpleCoin in figure 6.4 is a UML symbol that stands for depends on. I’ve included the arrow because the SimpleCrowdsale contract has a state variable of type Releasable-SimpleCoin, so it depends on ReleasableSimpleCoin.
Figure 6.4. Crowdsale’s contract diagram, including Ownable contract and token contract. Both SimpleCrowdsale and SimpleCoin are inherited from Ownable. SimpleCrowdsale has a ReleasableSimpleCoin state variable, so it depends on ReleasableSimpleCoin. (If you’re unfamiliar with objectoriented class diagrams, the hollow-headed arrow means “inherited from,” and the filled arrow means “depends on.”)
![]()
You’ve just started implementing SimpleCrowdsale, but if you want to see what you’ve built so far in action, copy listing 6.5 into a new Remix code tab (perhaps named Listing6_5_SimpleCrowdsale.sol). Make sure you’ve placed the dependent code specified in the import directives in related code tabs named appropriately: