Skip to content

Commit 144db43

Browse files
committed
2 parents f7c396b + 6b4ae0d commit 144db43

File tree

381 files changed

+3732
-5687
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

381 files changed

+3732
-5687
lines changed

PULL_REQUEST_TEMPLATE.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
Pull request title
3+
4+
- Clearly and concisely describes what it does
5+
- Refer to the issue that it solves, if available
6+
7+
8+
Pull request description
9+
10+
- Describes the main changes that come with the pull request
11+
- Any relevant additional information is provided
12+
13+
14+
15+
> For detailed contributing instructions see https://github.com/iluwatar/java-design-patterns/wiki/01.-How-to-contribute

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
[![License MIT](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/iluwatar/java-design-patterns/master/LICENSE.md)
99
[![Join the chat at https://gitter.im/iluwatar/java-design-patterns](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/iluwatar/java-design-patterns?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
1010
[![Quality Gate](https://sonarqube.com/api/badges/gate?key=com.iluwatar%3Ajava-design-patterns)](https://sonarqube.com/dashboard/index/com.iluwatar%3Ajava-design-patterns)
11+
[![CII Best Practices](https://bestpractices.coreinfrastructure.org/projects/1503/badge)](https://bestpractices.coreinfrastructure.org/projects/1503)
1112

1213
# Introduction
1314

_scripts/postPumlsToServer.py

Lines changed: 0 additions & 67 deletions
This file was deleted.

abstract-document/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ layout: pattern
33
title: Abstract Document
44
folder: abstract-document
55
permalink: /patterns/abstract-document/
6-
pumlid: PSjB3eCm34NHhPG599vtDyQn85L-ifzX-p3lxEf8Twj3MXGDQvyJMFubChxpKN767gucSq07iinEjSNDOACVNvoAUZr6MWoe3QVE_WRnxZ0Mf38b-hkIGlurX_MyehS7
76
categories: Structural
87
tags:
98
- Java

abstract-document/etc/abstract-document.urm.puml

Lines changed: 0 additions & 59 deletions
This file was deleted.

abstract-document/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
<parent>
3030
<artifactId>java-design-patterns</artifactId>
3131
<groupId>com.iluwatar</groupId>
32-
<version>1.17.0-SNAPSHOT</version>
32+
<version>1.18.0-SNAPSHOT</version>
3333
</parent>
3434
<artifactId>abstract-document</artifactId>
3535
<dependencies>

abstract-factory/README.md

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ layout: pattern
33
title: Abstract Factory
44
folder: abstract-factory
55
permalink: /patterns/abstract-factory/
6-
pumlid: PSZB3OD034NHLa81Czwd6sCC39gVxEUWT1_ssLmTtQLqgR5fM7sTmFGtaV6TZu8prd0r6HtQaMKqAZLk1XjT_E6qgPUZfyc0MdTgx0-8LuUn8ErFXdr98NypXxKyezKV
76
categories: Creational
87
tags:
98
- Java
@@ -120,6 +119,45 @@ king.getDescription(); // Output: This is the Elven king!
120119
army.getDescription(); // Output: This is the Elven Army!
121120
```
122121

122+
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.
123+
The client can use FactoryMaker to create the desired concrete factory which, in turn, will produce different concrete objects (Army, King, Castle).
124+
In this example, we also used an enum to parameterize which type of kingdom factory the client will ask for.
125+
126+
```
127+
public static class FactoryMaker {
128+
129+
public enum KingdomType {
130+
ELF, ORC
131+
}
132+
133+
public static KingdomFactory makeFactory(KingdomType type) {
134+
switch (type) {
135+
case ELF:
136+
return new ElfKingdomFactory();
137+
case ORC:
138+
return new OrcKingdomFactory();
139+
default:
140+
throw new IllegalArgumentException("KingdomType not supported.");
141+
}
142+
}
143+
}
144+
145+
public static void main(String[] args) {
146+
App app = new App();
147+
148+
LOGGER.info("Elf Kingdom");
149+
app.createKingdom(FactoryMaker.makeFactory(KingdomType.ELF));
150+
LOGGER.info(app.getArmy().getDescription());
151+
LOGGER.info(app.getCastle().getDescription());
152+
LOGGER.info(app.getKing().getDescription());
153+
154+
LOGGER.info("Orc Kingdom");
155+
app.createKingdom(FactoryMaker.makeFactory(KingdomType.ORC));
156+
-- similar use of the orc factory
157+
}
158+
```
159+
160+
123161
## Applicability
124162
Use the Abstract Factory pattern when
125163

@@ -141,6 +179,10 @@ Use the Abstract Factory pattern when
141179

142180
* Dependency injection in java hides the service class dependencies that can lead to runtime errors that would have been caught at compile time.
143181

182+
## Presentations
183+
184+
* [Abstract Factory Pattern](etc/presentation.html)
185+
144186
## Real world examples
145187

146188
* [javax.xml.parsers.DocumentBuilderFactory](http://docs.oracle.com/javase/8/docs/api/javax/xml/parsers/DocumentBuilderFactory.html)

abstract-factory/etc/diagram1.png

56.7 KB
Loading

abstract-factory/etc/diagram2.png

25.7 KB
Loading

0 commit comments

Comments
 (0)