-
Notifications
You must be signed in to change notification settings - Fork 323
/
Inheritance
153 lines (136 loc) · 5.07 KB
/
Inheritance
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;
/**
* @title Employee
* @dev Abstract contract defining common properties and behavior for employees.
*/
abstract contract Employee {
uint public idNumber; // Unique identifier for the employee
uint public managerId; // Identifier of the manager overseeing the employee
/**
* @dev Constructor to initialize idNumber and managerId.
* @param _idNumber The unique identifier for the employee.
* @param _managerId The identifier of the manager overseeing the employee.
*/
constructor(uint _idNumber, uint _managerId) {
idNumber = _idNumber;
managerId = _managerId;
}
/**
* @dev Abstract function to be implemented by derived contracts to get the annual cost of the employee.
* @return The annual cost of the employee.
*/
function getAnnualCost() public virtual returns (uint);
}
/**
* @title Salaried
* @dev Contract representing employees who are paid an annual salary.
*/
contract Salaried is Employee {
uint public annualSalary; // The annual salary of the employee
/**
* @dev Constructor to initialize the Salaried contract.
* @param _idNumber The unique identifier for the employee.
* @param _managerId The identifier of the manager overseeing the employee.
* @param _annualSalary The annual salary of the employee.
*/
constructor(uint _idNumber, uint _managerId, uint _annualSalary) Employee(_idNumber, _managerId) {
annualSalary = _annualSalary;
}
/**
* @dev Overrides the getAnnualCost function to return the annual salary of the employee.
* @return The annual salary of the employee.
*/
function getAnnualCost() public override view returns (uint) {
return annualSalary;
}
}
/**
* @title Hourly
* @dev Contract representing employees who are paid an hourly rate.
*/
contract Hourly is Employee {
uint public hourlyRate; // The hourly rate of the employee
/**
* @dev Constructor to initialize the Hourly contract.
* @param _idNumber The unique identifier for the employee.
* @param _managerId The identifier of the manager overseeing the employee.
* @param _hourlyRate The hourly rate of the employee.
*/
constructor(uint _idNumber, uint _managerId, uint _hourlyRate) Employee(_idNumber, _managerId) {
hourlyRate = _hourlyRate;
}
/**
* @dev Overrides the getAnnualCost function to calculate the annual cost based on the hourly rate.
* Assuming a full-time workload of 2080 hours per year.
* @return The annual cost of the employee.
*/
function getAnnualCost() public override view returns (uint) {
return hourlyRate * 2080;
}
}
/**
* @title Manager
* @dev Contract managing a list of employee IDs.
*/
contract Manager {
uint[] public employeeIds; // List of employee IDs
/**
* @dev Function to add a new employee ID to the list.
* @param _reportId The ID of the employee to be added.
*/
function addReport(uint _reportId) public {
employeeIds.push(_reportId);
}
/**
* @dev Function to reset the list of employee IDs.
*/
function resetReports() public {
delete employeeIds;
}
}
/**
* @title Salesperson
* @dev Contract representing salespeople who are paid hourly.
*/
contract Salesperson is Hourly {
/**
* @dev Constructor to initialize the Salesperson contract.
* @param _idNumber The unique identifier for the employee.
* @param _managerId The identifier of the manager overseeing the employee.
* @param _hourlyRate The hourly rate of the employee.
*/
constructor(uint _idNumber, uint _managerId, uint _hourlyRate)
Hourly(_idNumber, _managerId, _hourlyRate) {}
}
/**
* @title EngineeringManager
* @dev Contract representing engineering managers who are paid an annual salary and have managerial responsibilities.
*/
contract EngineeringManager is Salaried, Manager {
/**
* @dev Constructor to initialize the EngineeringManager contract.
* @param _idNumber The unique identifier for the employee.
* @param _managerId The identifier of the manager overseeing the employee.
* @param _annualSalary The annual salary of the employee.
*/
constructor(uint _idNumber, uint _managerId, uint _annualSalary)
Salaried(_idNumber, _managerId, _annualSalary) {}
}
/**
* @title InheritanceSubmission
* @dev Contract for deploying instances of Salesperson and EngineeringManager.
*/
contract InheritanceSubmission {
address public salesPerson; // Address of the deployed Salesperson instance
address public engineeringManager; // Address of the deployed EngineeringManager instance
/**
* @dev Constructor to initialize the InheritanceSubmission contract.
* @param _salesPerson Address of the deployed Salesperson instance.
* @param _engineeringManager Address of the deployed EngineeringManager instance.
*/
constructor(address _salesPerson, address _engineeringManager) {
salesPerson = _salesPerson;
engineeringManager = _engineeringManager;
}
}