-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathHideDelegate.java
51 lines (41 loc) · 1017 Bytes
/
HideDelegate.java
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
package ch7;
/*
* A client is calling a delegate class of an object
*
* Create methods on the sever to hide the delegate
*
* - Encapsulation means that objects need to know less about other parts of the system.
* Then when things change, fewer objects need to be told about the change - which makes
* the change easier to make
*/
class Person {
private Department _department;
public Department getDepartment() {
return _department;
}
public void setDepartment(Department arg) {
_department = arg;
}
}
class Department {
private String _chargeCode;
private Person _manager;
public Department(Person manager) {
_manager = manager;
}
public Person getManager() {
return _manager;
}
}
class PersonRefactored {
private Department _department;
public Department getDepartment() {
return _department;
}
public void setDepartment(Department arg) {
_department = arg;
}
public Person getManager() {
return _department.getManager();
}
}