Skip to content

Commit f6d4397

Browse files
iluwatarohbus
andauthored
docs: Grammatical fixes for Abstract Factory (iluwatar#1782)
* Grammatical fixes * Update abstract-factory/README.md Co-authored-by: Subhrodip Mohanta <hello@subho.xyz>
1 parent c0d3689 commit f6d4397

File tree

10 files changed

+32
-35
lines changed

10 files changed

+32
-35
lines changed

abstract-factory/README.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ objects without specifying their concrete classes.
2020

2121
## Explanation
2222

23-
Real world example
23+
Real-world example
2424

25-
> To create a kingdom we need objects with a common theme. Elven kingdom needs an Elven king, Elven castle and Elven army whereas Orcish kingdom needs an Orcish king, Orcish castle and Orcish army. There is a dependency between the objects in the kingdom.
25+
> To create a kingdom we need objects with a common theme. The elven kingdom needs an elven king, elven castle, and elven army whereas the orcish kingdom needs an orcish king, orcish castle, and orcish army. There is a dependency between the objects in the kingdom.
2626
2727
In plain words
2828

@@ -34,7 +34,7 @@ Wikipedia says
3434
3535
**Programmatic Example**
3636

37-
Translating the kingdom example above. First of all we have some interfaces and implementation for the objects in the
37+
Translating the kingdom example above. First of all, we have some interfaces and implementation for the objects in the
3838
kingdom.
3939

4040
```java
@@ -52,21 +52,21 @@ public interface Army {
5252

5353
// Elven implementations ->
5454
public class ElfCastle implements Castle {
55-
static final String DESCRIPTION = "This is the Elven castle!";
55+
static final String DESCRIPTION = "This is the elven castle!";
5656
@Override
5757
public String getDescription() {
5858
return DESCRIPTION;
5959
}
6060
}
6161
public class ElfKing implements King {
62-
static final String DESCRIPTION = "This is the Elven king!";
62+
static final String DESCRIPTION = "This is the elven king!";
6363
@Override
6464
public String getDescription() {
6565
return DESCRIPTION;
6666
}
6767
}
6868
public class ElfArmy implements Army {
69-
static final String DESCRIPTION = "This is the Elven Army!";
69+
static final String DESCRIPTION = "This is the elven Army!";
7070
@Override
7171
public String getDescription() {
7272
return DESCRIPTION;
@@ -77,7 +77,7 @@ public class ElfArmy implements Army {
7777

7878
```
7979

80-
Then we have the abstraction and implementations for the kingdom factory
80+
Then we have the abstraction and implementations for the kingdom factory.
8181

8282
```java
8383
public interface KingdomFactory {
@@ -111,7 +111,7 @@ public class OrcKingdomFactory implements KingdomFactory {
111111
}
112112
```
113113

114-
Now we have our abstract factory that lets us make family of related objects i.e. Elven kingdom factory creates Elven castle, king and army etc.
114+
Now we have the abstract factory that lets us make a family of related objects i.e. elven kingdom factory creates elven castle, king and army, etc.
115115

116116
```java
117117
var factory = new ElfKingdomFactory();
@@ -127,13 +127,13 @@ army.getDescription();
127127
Program output:
128128

129129
```java
130-
This is the Elven castle!
131-
This is the Elven king!
132-
This is the Elven Army!
130+
This is the elven castle!
131+
This is the elven king!
132+
This is the elven Army!
133133
```
134134

135-
Now, we can design a factory for our different kingdom factories. In this example, we created FactoryMaker, responsible for returning an instance of either ElfKingdomFactory or OrcKingdomFactory.
136-
The client can use FactoryMaker to create the desired concrete factory which, in turn, will produce different concrete objects (Army, King, Castle).
135+
Now, we can design a factory for our different kingdom factories. In this example, we created `FactoryMaker`, responsible for returning an instance of either `ElfKingdomFactory` or `OrcKingdomFactory`.
136+
The client can use `FactoryMaker` to create the desired concrete factory which, in turn, will produce different concrete objects (derived from `Army`, `King`, `Castle`).
137137
In this example, we also used an enum to parameterize which type of kingdom factory the client will ask for.
138138

139139
```java
@@ -179,8 +179,8 @@ public static void main(String[] args) {
179179

180180
Use the Abstract Factory pattern when
181181

182-
* The system should be independent of how its products are created, composed and represented
183-
* The system should be configured with one of multiple families of products
182+
* The system should be independent of how its products are created, composed, and represented
183+
* The system should be configured with one of the multiple families of products
184184
* The family of related product objects is designed to be used together, and you need to enforce this constraint
185185
* You want to provide a class library of products, and you want to reveal just their interfaces, not their implementations
186186
* The lifetime of the dependency is conceptually shorter than the lifetime of the consumer.
@@ -200,7 +200,7 @@ Example use cases
200200

201201
* Dependency injection in java hides the service class dependencies that can lead to runtime errors that would have been caught at compile time.
202202
* While the pattern is great when creating predefined objects, adding the new ones might be challenging.
203-
* The code becomes more complicated than it should be, since a lot of new interfaces and classes are introduced along with the pattern.
203+
* The code becomes more complicated than it should be since a lot of new interfaces and classes are introduced along with the pattern.
204204

205205
## Tutorial
206206

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
*
3838
* <p>The essence of the Abstract Factory pattern is a factory interface ({@link KingdomFactory})
3939
* and its implementations ( {@link ElfKingdomFactory}, {@link OrcKingdomFactory}). The example uses
40-
* both concrete implementations to create a king, a castle and an army.
40+
* both concrete implementations to create a king, a castle, and an army.
4141
*/
4242
@Slf4j
4343
public class App implements Runnable {
@@ -60,13 +60,13 @@ public static void main(String[] args) {
6060

6161
@Override
6262
public void run() {
63-
LOGGER.info("Elf Kingdom");
63+
LOGGER.info("elf kingdom");
6464
createKingdom(Kingdom.FactoryMaker.KingdomType.ELF);
6565
LOGGER.info(kingdom.getArmy().getDescription());
6666
LOGGER.info(kingdom.getCastle().getDescription());
6767
LOGGER.info(kingdom.getKing().getDescription());
6868

69-
LOGGER.info("Orc Kingdom");
69+
LOGGER.info("orc kingdom");
7070
createKingdom(Kingdom.FactoryMaker.KingdomType.ORC);
7171
LOGGER.info(kingdom.getArmy().getDescription());
7272
LOGGER.info(kingdom.getCastle().getDescription());

abstract-factory/src/main/java/com/iluwatar/abstractfactory/ElfArmy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
*/
2929
public class ElfArmy implements Army {
3030

31-
static final String DESCRIPTION = "This is the Elven Army!";
31+
static final String DESCRIPTION = "This is the elven army!";
3232

3333
@Override
3434
public String getDescription() {

abstract-factory/src/main/java/com/iluwatar/abstractfactory/ElfCastle.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
*/
2929
public class ElfCastle implements Castle {
3030

31-
static final String DESCRIPTION = "This is the Elven castle!";
31+
static final String DESCRIPTION = "This is the elven castle!";
3232

3333
@Override
3434
public String getDescription() {

abstract-factory/src/main/java/com/iluwatar/abstractfactory/ElfKing.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
*/
2929
public class ElfKing implements King {
3030

31-
static final String DESCRIPTION = "This is the Elven king!";
31+
static final String DESCRIPTION = "This is the elven king!";
3232

3333
@Override
3434
public String getDescription() {

abstract-factory/src/main/java/com/iluwatar/abstractfactory/OrcArmy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
*/
2929
public class OrcArmy implements Army {
3030

31-
static final String DESCRIPTION = "This is the Orc Army!";
31+
static final String DESCRIPTION = "This is the orc army!";
3232

3333
@Override
3434
public String getDescription() {

abstract-factory/src/main/java/com/iluwatar/abstractfactory/OrcCastle.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
*/
2929
public class OrcCastle implements Castle {
3030

31-
static final String DESCRIPTION = "This is the Orc castle!";
31+
static final String DESCRIPTION = "This is the orc castle!";
3232

3333
@Override
3434
public String getDescription() {

abstract-factory/src/main/java/com/iluwatar/abstractfactory/OrcKing.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
*/
2929
public class OrcKing implements King {
3030

31-
static final String DESCRIPTION = "This is the Orc king!";
31+
static final String DESCRIPTION = "This is the orc king!";
3232

3333
@Override
3434
public String getDescription() {

abstract-factory/src/test/java/com/iluwatar/abstractfactory/AbstractFactoryTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@
2929
import static org.junit.jupiter.api.Assertions.assertTrue;
3030

3131
/**
32-
* Test for abstract factory.
32+
* Tests for abstract factory.
3333
*/
3434
class AbstractFactoryTest {
3535

3636
private final App app = new App();
3737

3838
@Test
39-
void king() {
39+
void verifyKingCreation() {
4040
app.createKingdom(Kingdom.FactoryMaker.KingdomType.ELF);
4141
final var kingdom = app.getKingdom();
4242

@@ -51,7 +51,7 @@ void king() {
5151
}
5252

5353
@Test
54-
void castle() {
54+
void verifyCastleCreation() {
5555
app.createKingdom(Kingdom.FactoryMaker.KingdomType.ELF);
5656
final var kingdom = app.getKingdom();
5757

@@ -66,7 +66,7 @@ void castle() {
6666
}
6767

6868
@Test
69-
void army() {
69+
void verifyArmyCreation() {
7070
app.createKingdom(Kingdom.FactoryMaker.KingdomType.ELF);
7171
final var kingdom = app.getKingdom();
7272

@@ -81,7 +81,7 @@ void army() {
8181
}
8282

8383
@Test
84-
void createElfKingdom() {
84+
void verifyElfKingdomCreation() {
8585
app.createKingdom(Kingdom.FactoryMaker.KingdomType.ELF);
8686
final var kingdom = app.getKingdom();
8787

@@ -97,7 +97,7 @@ void createElfKingdom() {
9797
}
9898

9999
@Test
100-
void createOrcKingdom() {
100+
void verifyOrcKingdomCreation() {
101101
app.createKingdom(Kingdom.FactoryMaker.KingdomType.ORC);
102102
final var kingdom = app.getKingdom();
103103

abstract-factory/src/test/java/com/iluwatar/abstractfactory/AppTest.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,7 @@
2828
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
2929

3030
/**
31-
* Issue: Add at least one assertion to this test case.
32-
*
33-
* Solution: Inserted assertion to check whether the execution of the main method in {@link App}
34-
* throws an exception.
31+
* Check whether the execution of the main method in {@link App} throws an exception.
3532
*/
3633
class AppTest {
3734

0 commit comments

Comments
 (0)