Skip to content

Commit 6ea6214

Browse files
committed
Add java 8 design patterns
1 parent 8515e49 commit 6ea6214

39 files changed

Lines changed: 692 additions & 0 deletions

‎.gitignore‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.classpath
2+
.project
3+
.settings/
4+
target/

‎pom.xml‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2+
<modelVersion>4.0.0</modelVersion>
3+
<groupId>com.fe</groupId>
4+
<artifactId>java8DesignPattern</artifactId>
5+
<version>0.0.1-SNAPSHOT</version>
6+
7+
<dependencies>
8+
<dependency>
9+
<groupId>junit</groupId>
10+
<artifactId>junit</artifactId>
11+
<version>4.8.1</version>
12+
</dependency>
13+
</dependencies>
14+
</project>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package java8.chainofresponsability.payment;
2+
3+
public class PaymentObj {
4+
private int amount;
5+
6+
public PaymentObj(int amount) {
7+
this.amount = amount;
8+
}
9+
10+
public int getAmount() {
11+
return amount;
12+
}
13+
14+
public void setAmount(int amount) {
15+
this.amount = amount;
16+
}
17+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package java8.chainofresponsability.payment;
2+
3+
public abstract class PaymentProcessor {
4+
5+
private PaymentProcessor next;
6+
7+
public void setNext(PaymentProcessor processor){
8+
if(next == null ){
9+
next = processor;
10+
} else {
11+
next.setNext(processor);
12+
}
13+
}
14+
15+
public PaymentObj process(PaymentObj p){
16+
handle(p);
17+
if(next != null ){
18+
return next.process(p);
19+
} else {
20+
return p;
21+
}
22+
}
23+
24+
protected abstract void handle(PaymentObj p);
25+
26+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package java8.chainofresponsability.payment;
2+
3+
public class PaymentProcessorA extends PaymentProcessor{
4+
5+
@Override
6+
protected void handle(PaymentObj p) {
7+
System.out.println("PaymentProcessorA amount: " + p.getAmount());
8+
}
9+
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package java8.chainofresponsability.payment;
2+
3+
public class PaymentProcessorB extends PaymentProcessor{
4+
5+
@Override
6+
protected void handle(PaymentObj p) {
7+
System.out.println("PaymentProcessoB amount: " + p.getAmount());
8+
}
9+
10+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package java8.decorator.functions;
2+
3+
public class Packing {
4+
5+
public static Integer giftPacking(Integer value){
6+
return 15 + value;
7+
}
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package java8.decorator.functions;
2+
3+
public class Taxes {
4+
5+
public static Integer international(Integer value){
6+
return 50 + value;
7+
}
8+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package java8.decorator.item;
2+
3+
public class Book implements Item {
4+
private int price;
5+
6+
public Book(int price) {
7+
this.price = price;
8+
}
9+
@Override
10+
public int getPrice() {
11+
return price;
12+
}
13+
14+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package java8.decorator.item;
2+
3+
//Implementing Decorator Design pattern
4+
public class GiftPacking extends ItemExtras{
5+
6+
public GiftPacking(Item item) {
7+
super(item);
8+
}
9+
10+
@Override
11+
public int getPrice() {
12+
return 15 + super.getPrice();
13+
}
14+
15+
}

0 commit comments

Comments
 (0)