-
Notifications
You must be signed in to change notification settings - Fork 1
/
2-3-composite.vala
70 lines (52 loc) · 1.62 KB
/
2-3-composite.vala
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
interface Employee : Object {
protected abstract string pname {protected get; protected set;}
protected abstract float psalary {protected get; protected set;}
// no overridable construct
public string get_name () {
return pname;
}
public void set_salary (float salary) {
psalary = salary;
}
public float get_salary () {
return psalary;
}
}
class Developer : Object, Employee {
protected string pname {protected get; protected set;}
protected float psalary {protected get; protected set;}
public Developer (string name, float salary) {
pname = name;
psalary = salary;
}
}
class Designer : Object, Employee {
protected string pname {protected get; protected set;}
protected float psalary {protected get; protected set;}
public Designer (string name, float salary) {
pname = name;
psalary = salary;
}
}
class Organization {
protected List<Employee> employees;
public void add_employee (Employee employee) {
employees.append (employee);
}
public float get_net_salaries () {
float net_salary = 0;
foreach (var employee in employees) {
net_salary += employee.get_salary ();
}
return net_salary;
}
}
public int main (string[] args) {
var john = new Developer ("John Doe", 12000);
var jane = new Developer ("Jane", 10000);
var organization = new Organization ();
organization.add_employee (john);
organization.add_employee (jane);
print ("Net salaries: " + organization.get_net_salaries ().to_string () + "\n");
return 0;
}