Skip to content

Commit 0bf2a2f

Browse files
committed
Merged from master
2 parents 363d2c3 + 0989c9b commit 0bf2a2f

File tree

103 files changed

+972
-221
lines changed

Some content is hidden

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

103 files changed

+972
-221
lines changed

README.md

Lines changed: 8 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,23 @@
66

77
[![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)
88

9-
![Build status](https://travis-ci.org/iluwatar/java-design-patterns.svg?branch=master) [![Coverage Status](https://coveralls.io/repos/iluwatar/java-design-patterns/badge.svg?branch=master)](https://coveralls.io/r/iluwatar/java-design-patterns?branch=master) <a href="https://scan.coverity.com/projects/5634">
9+
[![Build status](https://travis-ci.org/iluwatar/java-design-patterns.svg?branch=master)](https://travis-ci.org/iluwatar/java-design-patterns) [![Coverage Status](https://coveralls.io/repos/iluwatar/java-design-patterns/badge.svg?branch=master)](https://coveralls.io/r/iluwatar/java-design-patterns?branch=master) <a href="https://scan.coverity.com/projects/5634">
1010
<img alt="Coverity Scan Build Status"
1111
src="https://scan.coverity.com/projects/5634/badge.svg"/>
1212
</a>
1313

1414

15-
#### Browse and view all of the patterns on our Website: [iluwatar.github.io/java-design-patterns/](https://iluwatar.github.io/java-design-patterns/)
16-
1715
<a name="top"/>
1816

1917
# <a name="toc">Table of Contents</a>
2018
- <a href="#introduction">Introduction</a>
19+
- <a href="#contribute">How to contribute</a>
2120
- <a href="#faq">Frequently Asked Questions</a>
22-
- <a href="#how-to-contribute">How to contribute</a>
23-
- <a href="#versioning">Versioning</a>
2421
- <a href="#credits">Credits</a>
2522
- <a href="#license">License</a>
2623

2724

28-
## <a name="introduction">Introduction</a>
25+
# <a name="introduction">Introduction</a> [&#8593;](#top)
2926

3027
Design patterns are formalized best practices that the programmer can use to
3128
solve common problems when designing an application or system.
@@ -38,6 +35,11 @@ problems, and it also improves code readability for coders and architects who
3835
are familiar with the patterns.
3936

4037

38+
# <a name="contribute">How to contribute</a> [&#8593;](#top)
39+
40+
If you are willing to contribute to the project you will find the relevant information in our [developer wiki](https://github.com/iluwatar/java-design-patterns/wiki).
41+
42+
4143
# <a name="faq">Frequently asked questions</a> [&#8593;](#top)
4244

4345
**<a id="Q1">Q: What is the difference between State and Strategy patterns?</a>**
@@ -97,120 +99,18 @@ blocked waiting for available object from the pool. This is not the case with
9799
Flyweight.
98100

99101

100-
101-
# <a name="how-to-contribute">How to contribute</a> [&#8593;](#top)
102-
103-
**To work on a new pattern** you need to do the following steps:
104-
105-
1. If there is no issue for the new pattern yet, raise new issue. Comment on
106-
the issue that you are working on it so that others don't start work on the
107-
same thing.
108-
2. Fork the repository.
109-
3. Create a new folder for the pattern. The rough structure of the new folder would be as follows:
110-
* etc (every resource related to the pattern, like diagrams)
111-
* src (the source code of the pattern)
112-
* index.md (the description of the pattern)
113-
* pom.xml (the maven pom.xml)
114-
4. Implement the code changes in your fork. Remember to add sufficient comments
115-
documenting the implementation. Reference the issue id e.g. #52 in your
116-
commit messages.
117-
5. Format the code according to [Google Java Style Guide](https://google.github.io/styleguide/javaguide.html)
118-
* [Eclipse configuration](https://github.com/google/styleguide/blob/gh-pages/eclipse-java-google-style.xml)
119-
* [IntelliJ configuration](https://github.com/google/styleguide/blob/gh-pages/intellij-java-google-style.xml)
120-
6. Create a simple class diagram from your example code and put it inside of the etc folder.
121-
7. Add description of the pattern in index.md and link to the class diagram.
122-
(Attention, all internal links must be relative to the pattern subdirectory, else the links dont link properly on the website)
123-
8. Create a pull request.
124-
125-
**Structure of the index.md file**
126-
127-
```markdown
128-
--- # this is so called 'Yaml Front Matter', read up on it here: http://jekyllrb.com/docs/frontmatter/
129-
layout: pattern # layout must allways be pattern
130-
title: Best Pattern Ever # the properly formatted title
131-
folder: best-pattern-ever # the folder name in which this pattern lies
132-
permalink: /patterns/best-pattern-ever/ # the permalink to the pattern, to keep this uniform please stick to /patterns/FOLDER/
133-
134-
# both categories and tags are Yaml Lists
135-
# you can either just pick one or write a list with '-'s
136-
# usable categories and tags are listed here: https://github.com/iluwatar/java-design-patterns/blob/gh-pages/_config.yml
137-
categories: creational # categories of the pattern
138-
tags: # tags of the pattern
139-
- best
140-
- ever
141-
- awesome
142-
---
143-
144-
**Intent:** Makes your code awesome
145-
146-
![alt text](./etc/best_pattern.png "Best Pattern Ever")
147-
148-
**Applicability:** Use the Best Pattern Ever pattern when
149-
150-
* you want to be the best
151-
* you need to ...
152-
153-
**Real world examples:**
154-
155-
* [Nowhere](http://no.where.com)
156-
```
157-
158-
**To add a new category or tag** you need to edit the _config.yml file of the gh-pages branch.
159-
In there you should find 2 yaml lists with the respective names 'category-list' and 'tag-list'
160-
161-
**To work on one of the non-pattern issues** you need to do the following steps:
162-
163-
1. Check that the issue has "help wanted" badge
164-
2. Comment on the issue that you are working on it
165-
3. Fork the repository.
166-
4. Implement the code changes in your fork. Remember to add sufficient comments
167-
documenting the implementation. Reference the issue id e.g. #52 in your
168-
commit messages.
169-
5. Create a pull request.
170-
171-
**For creating/editing UML diagrams** you need [ObjectAid UML Explorer for Eclipse](http://www.objectaid.com/home).
172-
173-
**For inspiration** check out the following sources:
174-
175-
* there is a good list of design patterns at [Wikipedia](http://en.wikipedia.org/wiki/Software_design_pattern)
176-
* Martin Fowler's [Catalog of Patterns of Enterprise Application Architecture](http://martinfowler.com/eaaCatalog/)
177-
* [pattern language for microservices](http://microservices.io/patterns/index.html)
178-
* Microsoft's [Cloud Design Patterns](http://download.microsoft.com/download/B/B/6/BB69622C-AB5D-4D5F-9A12-B81B952C1169/CloudDesignPatternsBook-PDF.pdf)
179-
180-
**Links to patterns applied in real world applications** are welcome. The links
181-
should be added to the corresponding section of the `index.md`.
182-
183-
184-
# <a name="versioning">Versioning</a> [&#8593;](#top)
185-
186-
Java-design-patterns project uses [semantic versioning](http://semver.org/)
187-
scheme. However, version numbers in this project do not signify binary releases
188-
(since we don't make any) but rather milestones achieved on the roadmap. In
189-
other words, version numbers are used only for project planning sake.
190-
191-
192102
# <a name="credits">Credits</a> [&#8593;](#top)
193103

194104
* [Design Patterns: Elements of Reusable Object-Oriented Software](http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612)
195105
* [Effective Java (2nd Edition)](http://www.amazon.com/Effective-Java-Edition-Joshua-Bloch/dp/0321356683)
196106
* [Java Generics and Collections](http://www.amazon.com/Java-Generics-Collections-Maurice-Naftalin/dp/0596527756/)
197107
* [Let's Modify the Objects-First Approach into Design-Patterns-First](http://edu.pecinovsky.cz/papers/2006_ITiCSE_Design_Patterns_First.pdf)
198108
* [Pattern Languages of Program Design](http://www.amazon.com/Pattern-Languages-Program-Design-Coplien/dp/0201607344/ref=sr_1_1)
199-
* [Martin Fowler - Event Aggregator](http://martinfowler.com/eaaDev/EventAggregator.html)
200-
* [TutorialsPoint - Intercepting Filter](http://www.tutorialspoint.com/design_pattern/intercepting_filter_pattern.htm)
201109
* [Presentation Tier Patterns](http://www.javagyan.com/tutorials/corej2eepatterns/presentation-tier-patterns)
202110
* [Functional Programming in Java: Harnessing the Power of Java 8 Lambda Expressions](http://www.amazon.com/Functional-Programming-Java-Harnessing-Expressions/dp/1937785467/ref=sr_1_1)
203-
* [Martin Fowler - Service Layer](http://martinfowler.com/eaaCatalog/serviceLayer.html)
204-
* [Martin Fowler - Specifications](http://martinfowler.com/apsupp/spec.pdf)
205-
* [Martin Fowler - Tolerant Reader](http://martinfowler.com/bliki/TolerantReader.html)
206-
* [Trygve Reenskaug - Model-view-controller](http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller)
207-
* [Flux - Application architecture for building user interfaces](http://facebook.github.io/flux/)
208-
* [Richard Pawson - Naked Objects](http://downloads.nakedobjects.net/resources/Pawson%20thesis.pdf)
209111
* [Patterns of Enterprise Application Architecture](http://www.amazon.com/Patterns-Enterprise-Application-Architecture-Martin/dp/0321127420)
210112
* [Spring Data](http://www.amazon.com/Spring-Data-Mark-Pollack/dp/1449323952/ref=sr_1_1)
211113
* [J2EE Design Patterns](http://www.amazon.com/J2EE-Design-Patterns-William-Crawford/dp/0596004273/ref=sr_1_2)
212-
* [Marco Castigliego - Step Builder](http://rdafbn.blogspot.co.uk/2012/07/step-builder-pattern_28.html)
213-
* [Douglas C. Schmidt and Charles D. Cranor - Half Sync/Half Async](http://www.cs.wustl.edu/~schmidt/PDF/PLoP-95.pdf)
214114
* [Pattern Oriented Software Architecture Vol I-V](http://www.amazon.com/Pattern-Oriented-Software-Architecture-Volume-Patterns/dp/0471958697)
215115

216116

abstract-factory/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>com.iluwatar</groupId>
77
<artifactId>java-design-patterns</artifactId>
8-
<version>1.5.0</version>
8+
<version>1.6.0</version>
99
</parent>
1010
<artifactId>abstract-factory</artifactId>
1111
<dependencies>
Lines changed: 52 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.iluwatar.abstractfactory;
22

3+
34
/**
45
*
56
* The essence of the Abstract Factory pattern is a factory interface
@@ -12,26 +13,61 @@
1213
*/
1314
public class App {
1415

15-
/**
16-
* Program entry point
17-
* @param args command line arguments
18-
*/
19-
public static void main(String[] args) {
20-
createKingdom(new ElfKingdomFactory());
21-
createKingdom(new OrcKingdomFactory());
22-
}
16+
private King king;
17+
private Castle castle;
18+
private Army army;
2319

2420
/**
2521
* Creates kingdom
2622
* @param factory
2723
*/
28-
public static void createKingdom(KingdomFactory factory) {
29-
King king = factory.createKing();
30-
Castle castle = factory.createCastle();
31-
Army army = factory.createArmy();
32-
System.out.println("The kingdom was created.");
33-
System.out.println(king);
34-
System.out.println(castle);
35-
System.out.println(army);
24+
public void createKingdom(final KingdomFactory factory) {
25+
setKing(factory.createKing());
26+
setCastle(factory.createCastle());
27+
setArmy(factory.createArmy());
28+
}
29+
30+
ElfKingdomFactory getElfKingdomFactory() {
31+
return new ElfKingdomFactory();
32+
}
33+
34+
OrcKingdomFactory getOrcKingdomFactory() {
35+
return new OrcKingdomFactory();
36+
}
37+
38+
King getKing(final KingdomFactory factory) {
39+
return factory.createKing();
40+
}
41+
42+
Castle getCastle(final KingdomFactory factory) {
43+
return factory.createCastle();
44+
}
45+
46+
Army getArmy(final KingdomFactory factory) {
47+
return factory.createArmy();
48+
}
49+
50+
public King getKing() {
51+
return king;
52+
}
53+
54+
private void setKing(final King king) {
55+
this.king = king;
56+
}
57+
58+
public Castle getCastle() {
59+
return castle;
60+
}
61+
62+
private void setCastle(final Castle castle) {
63+
this.castle = castle;
64+
}
65+
66+
public Army getArmy() {
67+
return army;
68+
}
69+
70+
private void setArmy(final Army army) {
71+
this.army = army;
3672
}
3773
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@
77
*/
88
public interface Army {
99

10+
String getDescription();
1011
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@
77
*/
88
public interface Castle {
99

10+
String getDescription();
1011
}

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
*/
88
public class ElfArmy implements Army {
99

10+
static final String DESCRIPTION = "This is the Elven Army!";
11+
1012
@Override
11-
public String toString() {
12-
return "This is the Elven Army!";
13+
public String getDescription() {
14+
return DESCRIPTION;
1315
}
14-
1516
}

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
*/
88
public class ElfCastle implements Castle {
99

10+
static final String DESCRIPTION = "This is the Elven castle!";
11+
1012
@Override
11-
public String toString() {
12-
return "This is the Elven castle!";
13+
public String getDescription() {
14+
return DESCRIPTION;
1315
}
14-
1516
}

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
*/
88
public class ElfKing implements King {
99

10+
static final String DESCRIPTION = "This is the Elven king!";
11+
1012
@Override
11-
public String toString() {
12-
return "This is the Elven king!";
13+
public String getDescription() {
14+
return DESCRIPTION;
1315
}
14-
1516
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@
77
*/
88
public interface King {
99

10+
String getDescription();
1011
}

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
*/
88
public class OrcArmy implements Army {
99

10+
static final String DESCRIPTION = "This is the Orc Army!";
11+
1012
@Override
11-
public String toString() {
12-
return "This is the Orcish Army!";
13+
public String getDescription() {
14+
return DESCRIPTION;
1315
}
14-
1516
}

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
*/
88
public class OrcCastle implements Castle {
99

10+
static final String DESCRIPTION = "This is the Orc castle!";
11+
1012
@Override
11-
public String toString() {
12-
return "This is the Orcish castle!";
13+
public String getDescription() {
14+
return DESCRIPTION;
1315
}
14-
1516
}

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
*/
88
public class OrcKing implements King {
99

10+
static final String DESCRIPTION = "This is the Orc king!";
11+
1012
@Override
11-
public String toString() {
12-
return "This is the Orc king!";
13+
public String getDescription() {
14+
return DESCRIPTION;
1315
}
14-
1516
}

0 commit comments

Comments
 (0)