Skip to content

Commit ddb23fc

Browse files
committed
Design Pattern - Day 3
1 parent 2e9938b commit ddb23fc

File tree

5 files changed

+123
-0
lines changed

5 files changed

+123
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package BehavioralDP.ChainOfResponsibilityDP;
2+
3+
//Yetki dagilimi icin abstract sinif
4+
public abstract class Approver {
5+
6+
Approver chief;
7+
8+
//parametreli const.
9+
public Approver(Approver chief) {
10+
this.chief = chief;
11+
}
12+
13+
//onaylanabilecek kredi limiti
14+
abstract boolean approveLoan(int amount);
15+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package BehavioralDP.ChainOfResponsibilityDP;
2+
3+
public class ChainOfResponsibilityRunner {
4+
5+
void chainOfResponsibilityDemo() {
6+
7+
Approver genelMudur = new GenelMudur();
8+
Approver mudur = new Mudur(genelMudur);
9+
Approver memur = new Memur(mudur);
10+
11+
System.out.println("Kredi verme limitleri : ");
12+
System.out.println("Memur icin maksimum : <100");
13+
System.out.println("Müdür icin maksimum : <500");
14+
System.out.println("Genel Müdür icin limit yok");
15+
16+
//islemler hep memur sinifi üzerinden yapilacak
17+
System.out.println("***********************");
18+
System.out.println("Müsterinin memurdan talep ettigi kredi miktari : 50");
19+
memur.approveLoan(50);
20+
21+
System.out.println("***********************");
22+
System.out.println("Müsterinin memurdan talep ettigi kredi miktari : 450");
23+
memur.approveLoan(450);
24+
25+
System.out.println("***********************");
26+
System.out.println("Müsterinin memurdan talep ettigi kredi miktari : 1050");
27+
memur.approveLoan(1050);
28+
29+
}
30+
31+
public static void main(String[] args) {
32+
33+
ChainOfResponsibilityRunner cor = new ChainOfResponsibilityRunner();
34+
cor.chainOfResponsibilityDemo();
35+
36+
}
37+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package BehavioralDP.ChainOfResponsibilityDP;
2+
3+
public class GenelMudur extends Approver {
4+
5+
6+
public GenelMudur() {
7+
super(null);
8+
}
9+
10+
@Override
11+
boolean approveLoan(int amount) {
12+
13+
System.out.println("Genel müdür onayladi...");
14+
System.out.println("************************");
15+
return true;
16+
17+
}
18+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package BehavioralDP.ChainOfResponsibilityDP;
2+
3+
public class Memur extends Approver {
4+
5+
6+
public Memur(Approver chief) {
7+
super(chief);
8+
}
9+
10+
@Override
11+
boolean approveLoan(int amount) { //150
12+
13+
if (amount < 100) {
14+
15+
System.out.println("Memur onayladi");
16+
System.out.println("*****************");
17+
return true;
18+
19+
} else if (chief != null) {
20+
21+
System.out.println("Miktar memurun onaylama siniri disinda, Sef'e yönlendiriliyor ");
22+
return chief.approveLoan(amount);
23+
24+
}
25+
return false;
26+
}
27+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package BehavioralDP.ChainOfResponsibilityDP;
2+
3+
public class Mudur extends Approver {
4+
5+
6+
public Mudur(Approver chief) {
7+
super(chief);
8+
}
9+
10+
@Override
11+
boolean approveLoan(int amount) {
12+
13+
if (amount < 500){
14+
15+
System.out.println("Müdür onayladi");
16+
System.out.println("*****************");
17+
return true;
18+
} else if (chief != null) {
19+
20+
System.out.println("Miktar müdürün onaylama siniri disinda, Sef'e yönlendiriliyor ");
21+
return chief.approveLoan(amount);
22+
23+
}
24+
return false;
25+
}
26+
}

0 commit comments

Comments
 (0)