-
Notifications
You must be signed in to change notification settings - Fork 0
/
abstract.sol
63 lines (54 loc) · 1.49 KB
/
abstract.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
pragma solidity ^0.5.12;
// Abstract contract, interface and inheritance
contract Animal{
// uint numberOfLegs;
bool alive =true;
// constructor(uint _numberOfLegs) public{
// numberOfLegs = _numberOfLegs;
// alive = true;
// }
function sound() public view returns(string memory);
function isIntell() public pure returns(bool);
function doesEat() public view returns(bool){
if (alive){
return true;
}
return false;
}
}
contract Hunter{
function useTools() public pure returns(bool);
}
contract Feline is Animal,Hunter{
function isMammal() public pure returns(bool){
return true;
}
function useTools() public pure returns(bool){
return false;
}
}
//concrete contract
contract Cat is Feline{
function sound() public view returns(string memory){
if (alive == true){
return "meow";
}
}
function isIntell() public pure returns(bool){
return false;
}
}
// order from most base to most derived
contract RightOrder is Animal, Feline{
function sound() public view returns(string memory){
if (alive == true){
return "meow";
}
}
function isIntell() public pure returns(bool){
return false;
}
}
// contract WrongOrder is Feline, Animal{
// // WrongOrder request Animal to override Feline but Feline wants to override Animal
// }