Skip to content

Commit 2884d05

Browse files
committed
solid principle SRP
1 parent 137346d commit 2884d05

File tree

5 files changed

+89
-0
lines changed

5 files changed

+89
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package solid_principles.srp;
2+
3+
public class Employee {
4+
private String empId;
5+
private String empName;
6+
7+
public String getEmpId() {
8+
return empId;
9+
}
10+
11+
public void setEmpId(String empId) {
12+
this.empId = empId;
13+
}
14+
15+
public String getEmpName() {
16+
return empName;
17+
}
18+
19+
public void setEmpName(String empName) {
20+
this.empName = empName;
21+
}
22+
23+
public void save() {
24+
// Saving employee to database
25+
// say mysql
26+
// in future if we want to change database
27+
// then we have to modify the employee code
28+
// so this can be moved
29+
}
30+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package solid_principles.srp;
2+
3+
public class EmployeeRepository {
4+
public void save(EmployeeSRP employeeSRP){
5+
6+
}
7+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package solid_principles.srp;
2+
3+
public class EmployeeSRP {
4+
private String empId;
5+
private String empName;
6+
7+
public String getEmpId() {
8+
return empId;
9+
}
10+
11+
public void setEmpId(String empId) {
12+
this.empId = empId;
13+
}
14+
15+
public String getEmpName() {
16+
return empName;
17+
}
18+
19+
public void setEmpName(String empName) {
20+
this.empName = empName;
21+
}
22+
23+
public void save() {
24+
new EmployeeRepository().save(this);
25+
}
26+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package solid_principles.srp;
2+
3+
// SRP - Single Responsibility Principle
4+
// High Cohesion
5+
// Loose coupling
6+
public class Square {
7+
// Related to measurements
8+
public void calculateArea() {
9+
10+
}
11+
12+
public void calculatePerimeter() {
13+
14+
}
15+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package solid_principles.srp;
2+
3+
public class SquareUI {
4+
public void rotate() {
5+
6+
}
7+
8+
public void draw() {
9+
10+
}
11+
}

0 commit comments

Comments
 (0)