Skip to content

Commit 60d8778

Browse files
authored
Merge pull request #1 from iluwatar/master
Fork Update
2 parents e7e3ace + 8475853 commit 60d8778

File tree

8 files changed

+149
-31
lines changed

8 files changed

+149
-31
lines changed

.all-contributorsrc

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,6 +1111,35 @@
11111111
"contributions": [
11121112
"code"
11131113
]
1114+
},
1115+
{
1116+
"login": "xdvrx1",
1117+
"name": "xdvrx1",
1118+
"avatar_url": "https://avatars0.githubusercontent.com/u/47092464?v=4",
1119+
"profile": "https://xdvrx1.github.io/",
1120+
"contributions": [
1121+
"review",
1122+
"ideas"
1123+
]
1124+
},
1125+
{
1126+
"login": "ohbus",
1127+
"name": "Subhrodip Mohanta",
1128+
"avatar_url": "https://avatars0.githubusercontent.com/u/13291222?v=4",
1129+
"profile": "http://subho.xyz",
1130+
"contributions": [
1131+
"code",
1132+
"review"
1133+
]
1134+
},
1135+
{
1136+
"login": "nahteb",
1137+
"name": "Bethan Palmer",
1138+
"avatar_url": "https://avatars3.githubusercontent.com/u/13121570?v=4",
1139+
"profile": "https://github.com/nahteb",
1140+
"contributions": [
1141+
"code"
1142+
]
11141143
}
11151144
],
11161145
"contributorsPerLine": 4,

.github/workflows/maven.yml renamed to .github/workflows/maven-ci.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,11 @@
2424
# This workflow will build a Java project with Maven
2525
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
2626

27-
name: Java CI with Maven
27+
name: Java CI
2828

2929
on:
3030
push:
3131
branches: [ master ]
32-
pull_request:
33-
branches: [ master ]
3432

3533
jobs:
3634
build:
@@ -43,6 +41,12 @@ jobs:
4341
uses: actions/setup-java@v1
4442
with:
4543
java-version: 11
44+
- uses: actions/cache@v2
45+
with:
46+
path: ~/.m2/repository
47+
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
48+
restore-keys: |
49+
${{ runner.os }}-maven-
4650
# Some tests need screen access
4751
- name: Install xvfb
4852
run: sudo apt-get install xvfb
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#
2+
# The MIT License
3+
# Copyright © 2014-2019 Ilkka Seppälä
4+
#
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy
6+
# of this software and associated documentation files (the "Software"), to deal
7+
# in the Software without restriction, including without limitation the rights
8+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
# copies of the Software, and to permit persons to whom the Software is
10+
# furnished to do so, subject to the following conditions:
11+
#
12+
# The above copyright notice and this permission notice shall be included in
13+
# all copies or substantial portions of the Software.
14+
#
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
# THE SOFTWARE.
22+
#
23+
24+
# This workflow will build a Java project with Maven
25+
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
26+
27+
name: Java PR Builder
28+
29+
on:
30+
pull_request:
31+
branches: [ master ]
32+
33+
jobs:
34+
build:
35+
36+
runs-on: ubuntu-18.04
37+
38+
steps:
39+
- uses: actions/checkout@v2
40+
- name: Set up JDK 11
41+
uses: actions/setup-java@v1
42+
with:
43+
java-version: 11
44+
- uses: actions/cache@v2
45+
with:
46+
path: ~/.m2/repository
47+
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
48+
restore-keys: |
49+
${{ runner.os }}-maven-
50+
# Some tests need screen access
51+
- name: Install xvfb
52+
run: sudo apt-get install xvfb
53+
# SonarQube scan does not work for forked repositories
54+
# See https://jira.sonarsource.com/browse/MMF-1371
55+
- name: Build with Maven
56+
if: github.ref != 'refs/heads/master'
57+
run: xvfb-run mvn clean verify

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
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
[![Sonarcloud Status](https://sonarcloud.io/api/project_badges/measure?project=iluwatar_java-design-patterns&metric=alert_status)](https://sonarcloud.io/dashboard?id=iluwatar_java-design-patterns)
1111
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
12-
[![All Contributors](https://img.shields.io/badge/all_contributors-122-orange.svg?style=flat-square)](#contributors-)
12+
[![All Contributors](https://img.shields.io/badge/all_contributors-125-orange.svg?style=flat-square)](#contributors-)
1313
<!-- ALL-CONTRIBUTORS-BADGE:END -->
1414

1515
# Introduction
@@ -251,6 +251,11 @@ This project is licensed under the terms of the MIT license.
251251
<tr>
252252
<td align="center"><a href="https://www.linkedin.com/in/ashish-trivedi-218379135/"><img src="https://avatars3.githubusercontent.com/u/23194128?v=4" width="100px;" alt=""/><br /><sub><b>Ashish Trivedi</b></sub></a><br /><a href="https://github.com/iluwatar/java-design-patterns/commits?author=ashishtrivedi16" title="Code">💻</a></td>
253253
<td align="center"><a href="https://rayyounghong.com"><img src="https://avatars1.githubusercontent.com/u/41055099?v=4" width="100px;" alt=""/><br /><sub><b>洪月阳</b></sub></a><br /><a href="https://github.com/iluwatar/java-design-patterns/commits?author=RayYH" title="Code">💻</a></td>
254+
<td align="center"><a href="https://xdvrx1.github.io/"><img src="https://avatars0.githubusercontent.com/u/47092464?v=4" width="100px;" alt=""/><br /><sub><b>xdvrx1</b></sub></a><br /><a href="https://github.com/iluwatar/java-design-patterns/pulls?q=is%3Apr+reviewed-by%3Axdvrx1" title="Reviewed Pull Requests">👀</a> <a href="#ideas-xdvrx1" title="Ideas, Planning, & Feedback">🤔</a></td>
255+
<td align="center"><a href="http://subho.xyz"><img src="https://avatars0.githubusercontent.com/u/13291222?v=4" width="100px;" alt=""/><br /><sub><b>Subhrodip Mohanta</b></sub></a><br /><a href="https://github.com/iluwatar/java-design-patterns/commits?author=ohbus" title="Code">💻</a> <a href="https://github.com/iluwatar/java-design-patterns/pulls?q=is%3Apr+reviewed-by%3Aohbus" title="Reviewed Pull Requests">👀</a></td>
256+
</tr>
257+
<tr>
258+
<td align="center"><a href="https://github.com/nahteb"><img src="https://avatars3.githubusercontent.com/u/13121570?v=4" width="100px;" alt=""/><br /><sub><b>Bethan Palmer</b></sub></a><br /><a href="https://github.com/iluwatar/java-design-patterns/commits?author=nahteb" title="Code">💻</a></td>
254259
</tr>
255260
</table>
256261

observer/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public class Orcs implements WeatherObserver {
4646

4747
@Override
4848
public void update(WeatherType currentWeather) {
49-
LOGGER.info("The hobbits are facing " + currentWeather.getDescription() + " weather now");
49+
LOGGER.info("The orcs are facing " + currentWeather.getDescription() + " weather now");
5050
}
5151
}
5252

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
<jaxb-impl.version>2.3.2</jaxb-impl.version>
5454
<annotation-api.version>1.3.2</annotation-api.version>
5555
<system-rules.version>1.19.0</system-rules.version>
56-
<urm.version>1.4.8</urm.version>
56+
<urm.version>2.0.0</urm.version>
5757
<!-- SonarCloud -->
5858
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
5959
<sonar.organization>iluwatar</sonar.organization>

unit-of-work/README.md

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,27 @@ tags:
1111
---
1212

1313
## Intent
14-
When a business transaction is completed, all the the updates are sent as one big unit of work to be persisted
15-
in one go to minimize database round-trips.
14+
15+
When a business transaction is completed, all the the updates are sent as one big unit of work to be
16+
persisted in one go to minimize database round-trips.
1617

1718
## Explanation
19+
1820
Real world example
1921

20-
> We have a database containing student information. Administrators all over the country are constantly updating this information and it causes high load on the database server. To make the load more manageable we apply to Unit of Work pattern to send many small updates in batches.
22+
> We have a database containing student information. Administrators all over the country are
23+
> constantly updating this information and it causes high load on the database server. To make the
24+
> load more manageable we apply to Unit of Work pattern to send many small updates in batches.
2125
2226
In plain words
2327

24-
> Unit of Work merges many small database updates in single batch to optimize the number of round-trips.
28+
> Unit of Work merges many small database updates in single batch to optimize the number of
29+
> round-trips.
2530
2631
[MartinFowler.com](https://martinfowler.com/eaaCatalog/unitOfWork.html) says
2732

28-
> Maintains a list of objects affected by a business transaction and coordinates the writing out of changes and the resolution of concurrency problems.
33+
> Maintains a list of objects affected by a business transaction and coordinates the writing out of
34+
> changes and the resolution of concurrency problems.
2935
3036
**Programmatic Example**
3137

@@ -57,8 +63,9 @@ public class Student {
5763
}
5864
```
5965

60-
The essence of the implementation is the `StudentRepository` implementing the Unit of Work pattern. It maintains a map
61-
of database operations (`context`) that need to be done and when `commit` is called it applies them in single batch.
66+
The essence of the implementation is the `StudentRepository` implementing the Unit of Work pattern.
67+
It maintains a map of database operations (`context`) that need to be done and when `commit` is
68+
called it applies them in single batch.
6269

6370
```java
6471
public interface IUnitOfWork<T> {
@@ -160,7 +167,7 @@ public class StudentRepository implements IUnitOfWork<Student> {
160167
}
161168
```
162169

163-
Finally here's how we use the `StudentRepository` and `commit` the transaction.
170+
Finally, here's how we use the `StudentRepository` and `commit` the transaction.
164171

165172
```java
166173
studentRepository.registerNew(ram);
@@ -170,9 +177,11 @@ Finally here's how we use the `StudentRepository` and `commit` the transaction.
170177
```
171178

172179
## Class diagram
180+
173181
![alt text](etc/unit-of-work.urm.png "unit-of-work")
174182

175183
## Applicability
184+
176185
Use the Unit Of Work pattern when
177186

178187
* To optimize the time taken for database transactions.

visitor/README.md

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,28 @@ tags:
99
---
1010

1111
## Intent
12-
Represent an operation to be performed on the elements of an object structure. Visitor lets you define a new operation without changing the classes of the elements on which it operates.
12+
13+
Represent an operation to be performed on the elements of an object structure. Visitor lets you
14+
define a new operation without changing the classes of the elements on which it operates.
1315

1416
## Explanation
1517

1618
Real world example
1719

18-
> Consider a tree structure with army units. Commander has two sergeants under it and each sergeant has three soldiers under them. Given that the hierarchy implements the visitor pattern, we can easily create new objects that interact with the commander, sergeants, soldiers or all of them.
20+
> Consider a tree structure with army units. Commander has two sergeants under it and each sergeant
21+
> has three soldiers under them. Given that the hierarchy implements the visitor pattern, we can
22+
> easily create new objects that interact with the commander, sergeants, soldiers or all of them.
1923
2024
In plain words
2125

2226
> Visitor pattern defines operations that can be performed on the nodes of the data structure.
2327
2428
Wikipedia says
2529

26-
> In object-oriented programming and software engineering, the visitor design pattern is a way of separating an algorithm from an object structure on which it operates. A practical result of this separation is the ability to add new operations to existing object structures without modifying the structures.
30+
> In object-oriented programming and software engineering, the visitor design pattern is a way of
31+
> separating an algorithm from an object structure on which it operates. A practical result of this
32+
> separation is the ability to add new operations to existing object structures without modifying
33+
> the structures.
2734
2835
**Programmatic Example**
2936

@@ -111,7 +118,7 @@ public class Soldier extends Unit {
111118
}
112119
```
113120

114-
And then some concrete visitors.
121+
Here are then some concrete visitors.
115122

116123
```java
117124
public class CommanderVisitor implements UnitVisitor {
@@ -175,32 +182,39 @@ public class SoldierVisitor implements UnitVisitor {
175182
}
176183
```
177184

178-
Finally we can show the power of visitors in action.
185+
Finally, we can show the power of visitors in action.
179186

180187
```java
181188
commander.accept(new SoldierVisitor());
182-
// Greetings soldier
183-
// Greetings soldier
184-
// Greetings soldier
185-
// Greetings soldier
186-
// Greetings soldier
187-
// Greetings soldier
188189
commander.accept(new SergeantVisitor());
189-
// Hello sergeant
190-
// Hello sergeant
191190
commander.accept(new CommanderVisitor());
192-
// Good to see you commander
191+
```
192+
193+
Program output:
194+
195+
```
196+
Greetings soldier
197+
Greetings soldier
198+
Greetings soldier
199+
Greetings soldier
200+
Greetings soldier
201+
Greetings soldier
202+
Hello sergeant
203+
Hello sergeant
204+
Good to see you commander
193205
```
194206

195207
## Class diagram
208+
196209
![alt text](./etc/visitor_1.png "Visitor")
197210

198211
## Applicability
212+
199213
Use the Visitor pattern when
200214

201-
* An object structure contains many classes of objects with differing interfaces, and you want to perform operations on these objects that depend on their concrete classes
202-
* Many distinct and unrelated operations need to be performed on objects in an object structure, and you want to avoid "polluting" their classes with these operations. Visitor lets you keep related operations together by defining them in one class. When the object structure is shared by many applications, use Visitor to put operations in just those applications that need them
203-
* The classes defining the object structure rarely change, but you often want to define new operations over the structure. Changing the object structure classes requires redefining the interface to all visitors, which is potentially costly. If the object structure classes change often, then it's probably better to define the operations in those classes
215+
* An object structure contains many classes of objects with differing interfaces, and you want to perform operations on these objects that depend on their concrete classes.
216+
* Many distinct and unrelated operations need to be performed on objects in an object structure, and you want to avoid "polluting" their classes with these operations. Visitor lets you keep related operations together by defining them in one class. When the object structure is shared by many applications, use Visitor to put operations in just those applications that need them.
217+
* The classes defining the object structure rarely change, but you often want to define new operations over the structure. Changing the object structure classes requires redefining the interface to all visitors, which is potentially costly. If the object structure classes change often, then it's probably better to define the operations in those classes.
204218

205219
## Real world examples
206220

0 commit comments

Comments
 (0)