Skip to content

Commit e89042a

Browse files
committed
remove boilerplate code
1 parent fb890e8 commit e89042a

2 files changed

Lines changed: 25 additions & 34 deletions

File tree

‎abstract-factory/pom.xml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@
3131
<artifactId>junit-jupiter-engine</artifactId>
3232
<scope>test</scope>
3333
</dependency>
34+
<dependency>
35+
<groupId>org.projectlombok</groupId>
36+
<artifactId>lombok</artifactId>
37+
<version>1.18.12</version>
38+
</dependency>
3439
</dependencies>
3540
<build>
3641
<plugins>

‎abstract-factory/src/main/java/com/iluwatar/abstractfactory/App.java‎

Lines changed: 20 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
package com.iluwatar.abstractfactory;
2525

2626
import com.iluwatar.abstractfactory.App.FactoryMaker.KingdomType;
27+
import lombok.Getter;
28+
import lombok.Setter;
29+
import lombok.extern.slf4j.Slf4j;
2730
import org.slf4j.Logger;
2831
import org.slf4j.LoggerFactory;
2932

@@ -41,12 +44,19 @@
4144
* and its implementations ( {@link ElfKingdomFactory}, {@link OrcKingdomFactory}). The example uses
4245
* both concrete implementations to create a king, a castle and an army.
4346
*/
47+
@Slf4j
4448
public class App {
4549

46-
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
47-
50+
@Setter
51+
@Getter
4852
private King king;
53+
54+
@Setter
55+
@Getter
4956
private Castle castle;
57+
58+
@Setter
59+
@Getter
5060
private Army army;
5161

5262
/**
@@ -58,30 +68,6 @@ public void createKingdom(final KingdomFactory factory) {
5868
setArmy(factory.createArmy());
5969
}
6070

61-
public King getKing() {
62-
return king;
63-
}
64-
65-
private void setKing(final King king) {
66-
this.king = king;
67-
}
68-
69-
public Castle getCastle() {
70-
return castle;
71-
}
72-
73-
private void setCastle(final Castle castle) {
74-
this.castle = castle;
75-
}
76-
77-
public Army getArmy() {
78-
return army;
79-
}
80-
81-
private void setArmy(final Army army) {
82-
this.army = army;
83-
}
84-
8571
/**
8672
* The factory of kingdom factories.
8773
*/
@@ -118,16 +104,16 @@ public static void main(String[] args) {
118104

119105
var app = new App();
120106

121-
LOGGER.info("Elf Kingdom");
107+
log.info("Elf Kingdom");
122108
app.createKingdom(FactoryMaker.makeFactory(KingdomType.ELF));
123-
LOGGER.info(app.getArmy().getDescription());
124-
LOGGER.info(app.getCastle().getDescription());
125-
LOGGER.info(app.getKing().getDescription());
109+
log.info(app.getArmy().getDescription());
110+
log.info(app.getCastle().getDescription());
111+
log.info(app.getKing().getDescription());
126112

127-
LOGGER.info("Orc Kingdom");
113+
log.info("Orc Kingdom");
128114
app.createKingdom(FactoryMaker.makeFactory(KingdomType.ORC));
129-
LOGGER.info(app.getArmy().getDescription());
130-
LOGGER.info(app.getCastle().getDescription());
131-
LOGGER.info(app.getKing().getDescription());
115+
log.info(app.getArmy().getDescription());
116+
log.info(app.getCastle().getDescription());
117+
log.info(app.getKing().getDescription());
132118
}
133119
}

0 commit comments

Comments
 (0)