forked from hacker85/JavaLessons
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSingleResponsibilityLesson.java
More file actions
62 lines (59 loc) · 1.11 KB
/
Copy pathSingleResponsibilityLesson.java
File metadata and controls
62 lines (59 loc) · 1.11 KB
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
package solid;
public class SingleResponsibilityLesson {
public static void main(String[] args) {
}
}
//Single responsibility
//A class should have only one reason to change
class Employee {
void cook() {}
void deliverFood() {}
void cleanFloor() {}
}
class Chef {
void cook(){}
}
class Waiter {
void deliverFood() {}
}
class JanitorEmployee {
void cleanFloor() {}
}
//-----------------------
class Employe {
int getPay() {return 100;}
}
class ChefEmp extends Employe {
void cook() {}
}
//------------
interface Emp {
int getPay();
}
class WaiterEmp implements Emp {
@Override
public int getPay() {
return 100;
}
void deliverFood() {
System.out.println("deliver food");
}
}
//--------------------------------
//facade
class ChefEmployee {
void cook() {}
}
class WaiterEmployee {
void deliverFood() {}
}
class Facade {
ChefEmployee chefEmployee = new ChefEmployee();
WaiterEmployee waiterEmployee = new WaiterEmployee();
void cook() {
chefEmployee.cook();
}
void deliverFood() {
waiterEmployee.deliverFood();
}
}