-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFactoryDemo.sol
69 lines (53 loc) · 1.5 KB
/
FactoryDemo.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
62
63
64
65
66
67
68
69
pragma solidity >=0.8.9 <=0.8.18;
contract Fastfood {
uint256 public total_calo; // state variable
uint8 private id;
bool private available;
enum TypeFastFood {
Hamburger,
Chips,
Tacos
}
struct Ingredient {
string name;
uint256 value;
}
mapping(string => uint256) public ingredient;
address public owner;
event AddIngredient(string name, uint256 calo);
function getIngredient(
string memory nameIngredient
) public view returns (uint256) {
uint256 calo = ingredient[nameIngredient];
return calo;
}
function addIngredient(string memory name, uint256 calo) public virtual {
ingredient[name] = calo;
emit AddIngredient(name, calo);
}
}
interface IFastfood {
function getIngredient(string memory) external view returns (uint256);
function addIngredient(string memory, uint256) external;
}
contract Snack is IFastfood {
function getIngredient(string memory name) external view returns (uint256) {
// ...
}
function addIngredient(string memory name, uint256 calo) external {
//...
}
}
abstract contract Food {
string public name = "Vegetable";
function getName() public view returns (string memory) {
// code ...
return name;
}
function changeName(string memory _name) external virtual;
}
contract Carrot is Food {
function changeName(string memory _name) public override {
name = _name;
}
}