Skip to content

Commit c48c753

Browse files
committed
Remove extra spaces and fix methods order
1 parent 54fa36e commit c48c753

28 files changed

Lines changed: 96 additions & 104 deletions

File tree

pom.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.github.gaboso</groupId>
88
<artifactId>java-design-patterns</artifactId>
9-
<version>1.0.0-SNAPSHOT</version>
9+
<version>1.0.0</version>
1010

1111
<properties>
1212
<java.version>11</java.version>
@@ -40,7 +40,6 @@
4040
<version>4.0.7</version>
4141
</dependency>
4242

43-
4443
</dependencies>
4544

4645
</project>

src/main/java/com/github/gaboso/behavior/command/receiver/Light.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ public void toggle() {
1818
}
1919
}
2020

21-
public void on() {
22-
System.out.println("Light switched on");
23-
}
24-
2521
public void off() {
2622
System.out.println("Light switched off");
2723
}
2824

25+
public void on() {
26+
System.out.println("Light switched on");
27+
}
28+
2929
}

src/main/java/com/github/gaboso/behavior/interpreter/InterpreterMain.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@
77

88
public class InterpreterMain {
99

10+
public static void main(String[] args) {
11+
String context = "Lions Bears";
12+
13+
Expression define = buildInterpreterTree();
14+
System.out.println(context + " is " + define.interpret(context));
15+
}
16+
1017
static Expression buildInterpreterTree() {
1118
Expression terminalLions = new TerminalExpression("Lions");
1219
Expression terminalTigers = new TerminalExpression("Tigers");
@@ -18,11 +25,4 @@ static Expression buildInterpreterTree() {
1825
return new AndExpression(terminalBears, lionsOrTigersAndBears);
1926
}
2027

21-
public static void main(String[] args) {
22-
String context = "Lions Bears";
23-
24-
Expression define = buildInterpreterTree();
25-
System.out.println(context + " is " + define.interpret(context));
26-
}
27-
2828
}

src/main/java/com/github/gaboso/behavior/mediator/MediatorMain.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
public class MediatorMain {
99

10-
1110
public static void main(String[] args) {
1211
var mediator = new Mediator();
1312

src/main/java/com/github/gaboso/behavior/mediator/receiver/Light.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ public void toggle() {
2727
}
2828
}
2929

30-
public void on() {
31-
System.out.println(location + " Light switched on");
32-
}
33-
3430
public void off() {
3531
System.out.println(location + " Light switched off");
3632
}
3733

34+
public void on() {
35+
System.out.println(location + " Light switched on");
36+
}
37+
3838
}

src/main/java/com/github/gaboso/behavior/memento/memento/EmployeeMemento.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ public class EmployeeMemento {
55
private String name;
66
private String phone;
77

8-
98
public EmployeeMemento(String name, String phone) {
109
this.name = name;
1110
this.phone = phone;

src/main/java/com/github/gaboso/behavior/observer/subject/MessageStream.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ public class MessageStream extends Subject {
88
private final Deque<String> messageHistory = new ArrayDeque<>();
99

1010
@Override
11-
public void setState(String message) {
12-
messageHistory.add(message);
13-
this.notifyObservers();
11+
public String getState() {
12+
return messageHistory.getLast();
1413
}
1514

1615
@Override
17-
public String getState() {
18-
return messageHistory.getLast();
16+
public void setState(String message) {
17+
messageHistory.add(message);
18+
this.notifyObservers();
1919
}
2020

2121
}

src/main/java/com/github/gaboso/behavior/observer/subject/Subject.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ public abstract class Subject {
99

1010
private final List<Observer> observers = new ArrayList<>();
1111

12-
public abstract void setState(String state);
13-
1412
public abstract String getState();
1513

14+
public abstract void setState(String state);
15+
1616
public void attach(Observer observer) {
1717
observers.add(observer);
1818
}

src/main/java/com/github/gaboso/behavior/strategy/StrategyMain.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,21 @@ public static void main(String[] args) {
1212
amexCard.setDate("04/2020");
1313
amexCard.setCvv("123");
1414

15-
System.out.println("Is Amex valid: "+ amexCard.isValid());
15+
System.out.println("Is Amex valid: " + amexCard.isValid());
1616

1717
var fakeAmexCard = new CreditCard(new AmexStrategy());
1818
fakeAmexCard.setNumber("3413024635796881");
1919
fakeAmexCard.setDate("09/2026");
2020
fakeAmexCard.setCvv("123");
2121

22-
System.out.println("Is Fake Amex valid: "+ fakeAmexCard.isValid());
22+
System.out.println("Is Fake Amex valid: " + fakeAmexCard.isValid());
2323

2424
var visaCard = new CreditCard(new VisaStrategy());
2525
visaCard.setNumber("4539978020235353");
2626
visaCard.setDate("03/2027");
2727
visaCard.setCvv("890");
2828

29-
System.out.println("Is Visa valid: "+ visaCard.isValid());
29+
System.out.println("Is Visa valid: " + visaCard.isValid());
3030
}
3131

3232
}

src/main/java/com/github/gaboso/behavior/template/template/OrderTemplate.java

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,6 @@ public abstract class OrderTemplate {
44

55
public boolean isGift;
66

7-
public abstract void doCheckout();
8-
9-
public abstract void doPayment();
10-
11-
public abstract void doReceipt();
12-
13-
public abstract void doDelivery();
14-
15-
public final void wrapGift() {
16-
System.out.println("Gift wrapped.");
17-
}
18-
197
public final void processOrder() {
208
doCheckout();
219
doPayment();
@@ -28,5 +16,16 @@ public final void processOrder() {
2816
doDelivery();
2917
}
3018

19+
public abstract void doCheckout();
20+
21+
public abstract void doPayment();
22+
23+
public final void wrapGift() {
24+
System.out.println("Gift wrapped.");
25+
}
26+
27+
public abstract void doReceipt();
28+
29+
public abstract void doDelivery();
3130

3231
}

0 commit comments

Comments
 (0)