From 0d2c4abe5abb0de934b0b170eaeb86dc6814ff42 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Sat, 15 Aug 2020 17:53:37 +0000 Subject: [PATCH 01/18] docs: update README.md [skip ci] --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2435298e7..8b52c40fc 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ [![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) [![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) -[![All Contributors](https://img.shields.io/badge/all_contributors-122-orange.svg?style=flat-square)](#contributors-) +[![All Contributors](https://img.shields.io/badge/all_contributors-123-orange.svg?style=flat-square)](#contributors-) # Introduction @@ -251,6 +251,7 @@ This project is licensed under the terms of the MIT license.
Ashish Trivedi

💻
洪月阳

💻 +
xdvrx1

👀 From a1c96ede139f50816ec710f3c07795c5b0aa2830 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Sat, 15 Aug 2020 17:53:38 +0000 Subject: [PATCH 02/18] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index 7a9aa42c4..484dd303b 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -1111,6 +1111,15 @@ "contributions": [ "code" ] + }, + { + "login": "xdvrx1", + "name": "xdvrx1", + "avatar_url": "https://avatars0.githubusercontent.com/u/47092464?v=4", + "profile": "https://xdvrx1.github.io/", + "contributions": [ + "review" + ] } ], "contributorsPerLine": 4, From 7afb065a108895a122bc18e1d2313dc1a3f6b9b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ilkka=20Sepp=C3=A4l=C3=A4?= Date: Sat, 15 Aug 2020 20:58:59 +0300 Subject: [PATCH 03/18] Upgrade urm plugin to latest version --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 9b3382795..0718ff045 100644 --- a/pom.xml +++ b/pom.xml @@ -53,7 +53,7 @@ 2.3.2 1.3.2 1.19.0 - 1.4.8 + 2.0.0 https://sonarcloud.io iluwatar From 00d06871f4841b676467bb933d7859713de0f306 Mon Sep 17 00:00:00 2001 From: Subhrodip Mohanta Date: Sun, 16 Aug 2020 12:42:08 +0530 Subject: [PATCH 04/18] updated workflows --- .github/workflows/{maven.yml => maven-ci.yml} | 10 ++- .github/workflows/maven-pr-builder.yml | 64 +++++++++++++++++++ 2 files changed, 71 insertions(+), 3 deletions(-) rename .github/workflows/{maven.yml => maven-ci.yml} (91%) create mode 100644 .github/workflows/maven-pr-builder.yml diff --git a/.github/workflows/maven.yml b/.github/workflows/maven-ci.yml similarity index 91% rename from .github/workflows/maven.yml rename to .github/workflows/maven-ci.yml index d18cad280..914db3f4d 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven-ci.yml @@ -24,13 +24,11 @@ # This workflow will build a Java project with Maven # For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven -name: Java CI with Maven +name: Java CI on: push: branches: [ master ] - pull_request: - branches: [ master ] jobs: build: @@ -43,6 +41,12 @@ jobs: uses: actions/setup-java@v1 with: java-version: 11 + - uses: actions/cache@v1 + with: + path: ~/.m2/repository + key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} + restore-keys: | + ${{ runner.os }}-maven- # Some tests need screen access - name: Install xvfb run: sudo apt-get install xvfb diff --git a/.github/workflows/maven-pr-builder.yml b/.github/workflows/maven-pr-builder.yml new file mode 100644 index 000000000..ea5d3d703 --- /dev/null +++ b/.github/workflows/maven-pr-builder.yml @@ -0,0 +1,64 @@ +# +# The MIT License +# Copyright © 2014-2019 Ilkka Seppälä +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. +# + +# This workflow will build a Java project with Maven +# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven + +name: Java PR Builder + +on: + pull_request: + branches: [ master ] + +jobs: + build: + + runs-on: ubuntu-18.04 + + steps: + - uses: actions/checkout@v2 + - name: Set up JDK 11 + uses: actions/setup-java@v1 + with: + java-version: 11 + - uses: actions/cache@v1 + with: + path: ~/.m2/repository + key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} + restore-keys: | + ${{ runner.os }}-maven- + # Some tests need screen access + - name: Install xvfb + run: sudo apt-get install xvfb + # SonarQube scan does not work for forked repositories + # See https://jira.sonarsource.com/browse/MMF-1371 + - name: Build with Maven + if: github.ref != 'refs/heads/master' + run: xvfb-run mvn clean verify + - name: Build with Maven and run SonarQube analysis + if: github.ref == 'refs/heads/master' + run: xvfb-run mvn clean verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar + env: + # These two env variables are needed for sonar analysis + GITHUB_TOKEN: ${{ secrets.REPOSITORY_ACCESS_TOKEN }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} From 79a6af703ec94e3719c05122e0c1c08768a877d6 Mon Sep 17 00:00:00 2001 From: Subhrodip Mohanta Date: Sun, 16 Aug 2020 12:49:21 +0530 Subject: [PATCH 05/18] updated copyright year to 2020 --- .github/workflows/maven-ci.yml | 2 +- .github/workflows/maven-pr-builder.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/maven-ci.yml b/.github/workflows/maven-ci.yml index 914db3f4d..a04b0021e 100644 --- a/.github/workflows/maven-ci.yml +++ b/.github/workflows/maven-ci.yml @@ -1,6 +1,6 @@ # # The MIT License -# Copyright © 2014-2019 Ilkka Seppälä +# Copyright © 2014-2020 Ilkka Seppälä # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal diff --git a/.github/workflows/maven-pr-builder.yml b/.github/workflows/maven-pr-builder.yml index ea5d3d703..0384c326c 100644 --- a/.github/workflows/maven-pr-builder.yml +++ b/.github/workflows/maven-pr-builder.yml @@ -1,6 +1,6 @@ # # The MIT License -# Copyright © 2014-2019 Ilkka Seppälä +# Copyright © 2014-2020 Ilkka Seppälä # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal From 241f93f3ccd6d83b16006ede3c5241f5feae480a Mon Sep 17 00:00:00 2001 From: Subhrodip Mohanta Date: Mon, 17 Aug 2020 11:28:33 +0530 Subject: [PATCH 06/18] updated cache to v2 and removed SQ analysis --- .github/workflows/maven-ci.yml | 2 +- .github/workflows/maven-pr-builder.yml | 9 +-------- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/.github/workflows/maven-ci.yml b/.github/workflows/maven-ci.yml index a04b0021e..8a7f7a0bb 100644 --- a/.github/workflows/maven-ci.yml +++ b/.github/workflows/maven-ci.yml @@ -41,7 +41,7 @@ jobs: uses: actions/setup-java@v1 with: java-version: 11 - - uses: actions/cache@v1 + - uses: actions/cache@v2 with: path: ~/.m2/repository key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} diff --git a/.github/workflows/maven-pr-builder.yml b/.github/workflows/maven-pr-builder.yml index 0384c326c..1bdad0621 100644 --- a/.github/workflows/maven-pr-builder.yml +++ b/.github/workflows/maven-pr-builder.yml @@ -41,7 +41,7 @@ jobs: uses: actions/setup-java@v1 with: java-version: 11 - - uses: actions/cache@v1 + - uses: actions/cache@v2 with: path: ~/.m2/repository key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} @@ -55,10 +55,3 @@ jobs: - name: Build with Maven if: github.ref != 'refs/heads/master' run: xvfb-run mvn clean verify - - name: Build with Maven and run SonarQube analysis - if: github.ref == 'refs/heads/master' - run: xvfb-run mvn clean verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar - env: - # These two env variables are needed for sonar analysis - GITHUB_TOKEN: ${{ secrets.REPOSITORY_ACCESS_TOKEN }} - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} From 89bda692f80b310e394219dbbb6b396f944db8c6 Mon Sep 17 00:00:00 2001 From: Bethan Palmer Date: Mon, 17 Aug 2020 07:47:30 +0100 Subject: [PATCH 07/18] Fix typo in README The log message in the Orcs class should say orcs instead of hobbits. This is correct in the code example but wrong in the README. --- observer/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/observer/README.md b/observer/README.md index e4b3cea76..d0ddf3c00 100644 --- a/observer/README.md +++ b/observer/README.md @@ -46,7 +46,7 @@ public class Orcs implements WeatherObserver { @Override public void update(WeatherType currentWeather) { - LOGGER.info("The hobbits are facing " + currentWeather.getDescription() + " weather now"); + LOGGER.info("The orcs are facing " + currentWeather.getDescription() + " weather now"); } } From 8c5740563dc5c1eb01c55bdcc919a70bb880d99d Mon Sep 17 00:00:00 2001 From: Subhrodip Mohanta Date: Mon, 17 Aug 2020 19:12:54 +0530 Subject: [PATCH 08/18] reverted the copyright year back to 2019 --- .github/workflows/maven-ci.yml | 2 +- .github/workflows/maven-pr-builder.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/maven-ci.yml b/.github/workflows/maven-ci.yml index 8a7f7a0bb..be0a74e9f 100644 --- a/.github/workflows/maven-ci.yml +++ b/.github/workflows/maven-ci.yml @@ -1,6 +1,6 @@ # # The MIT License -# Copyright © 2014-2020 Ilkka Seppälä +# Copyright © 2014-2019 Ilkka Seppälä # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal diff --git a/.github/workflows/maven-pr-builder.yml b/.github/workflows/maven-pr-builder.yml index 1bdad0621..7e4f3670f 100644 --- a/.github/workflows/maven-pr-builder.yml +++ b/.github/workflows/maven-pr-builder.yml @@ -1,6 +1,6 @@ # # The MIT License -# Copyright © 2014-2020 Ilkka Seppälä +# Copyright © 2014-2019 Ilkka Seppälä # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal From 353a2d9fcf294312816ccc1f091ff7e0937c16c3 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Mon, 17 Aug 2020 16:10:20 +0000 Subject: [PATCH 09/18] docs: update README.md [skip ci] --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8b52c40fc..2169889dd 100644 --- a/README.md +++ b/README.md @@ -251,7 +251,7 @@ This project is licensed under the terms of the MIT license.
Ashish Trivedi

💻
洪月阳

💻 -
xdvrx1

👀 +
xdvrx1

👀 🤔 From d584404df6c011c854cb3e3025b0072d7d422ddb Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Mon, 17 Aug 2020 16:10:21 +0000 Subject: [PATCH 10/18] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.all-contributorsrc b/.all-contributorsrc index 484dd303b..4bdc6c011 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -1118,7 +1118,8 @@ "avatar_url": "https://avatars0.githubusercontent.com/u/47092464?v=4", "profile": "https://xdvrx1.github.io/", "contributions": [ - "review" + "review", + "ideas" ] } ], From cfb58191ea58c12bb1060f6a4defa7e19ccae28e Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Mon, 17 Aug 2020 16:14:03 +0000 Subject: [PATCH 11/18] docs: update README.md [skip ci] --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2169889dd..36094b1db 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ [![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) [![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) -[![All Contributors](https://img.shields.io/badge/all_contributors-123-orange.svg?style=flat-square)](#contributors-) +[![All Contributors](https://img.shields.io/badge/all_contributors-124-orange.svg?style=flat-square)](#contributors-) # Introduction @@ -252,6 +252,7 @@ This project is licensed under the terms of the MIT license.
Ashish Trivedi

💻
洪月阳

💻
xdvrx1

👀 🤔 +
Subhrodip Mohanta

💻 From 7f60f7be25f4d1c39279aa49acee7a8dd215ec3c Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Mon, 17 Aug 2020 16:14:04 +0000 Subject: [PATCH 12/18] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index 4bdc6c011..6ea5a5de6 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -1121,6 +1121,15 @@ "review", "ideas" ] + }, + { + "login": "ohbus", + "name": "Subhrodip Mohanta", + "avatar_url": "https://avatars0.githubusercontent.com/u/13291222?v=4", + "profile": "http://subho.xyz", + "contributions": [ + "code" + ] } ], "contributorsPerLine": 4, From 95e513b6ecffbc7a1fbd194c1908e0f9f9adf2d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ilkka=20Sepp=C3=A4l=C3=A4?= Date: Mon, 17 Aug 2020 19:49:00 +0300 Subject: [PATCH 13/18] Edit readme --- visitor/README.md | 48 ++++++++++++++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 17 deletions(-) diff --git a/visitor/README.md b/visitor/README.md index c97e97120..75a032a47 100644 --- a/visitor/README.md +++ b/visitor/README.md @@ -9,13 +9,17 @@ tags: --- ## Intent -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. + +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. ## Explanation Real world example -> 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. +> 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. In plain words @@ -23,7 +27,10 @@ In plain words Wikipedia says -> 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. +> 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. **Programmatic Example** @@ -111,7 +118,7 @@ public class Soldier extends Unit { } ``` -And then some concrete visitors. +Here are then some concrete visitors. ```java public class CommanderVisitor implements UnitVisitor { @@ -175,32 +182,39 @@ public class SoldierVisitor implements UnitVisitor { } ``` -Finally we can show the power of visitors in action. +Finally, we can show the power of visitors in action. ```java commander.accept(new SoldierVisitor()); -// Greetings soldier -// Greetings soldier -// Greetings soldier -// Greetings soldier -// Greetings soldier -// Greetings soldier commander.accept(new SergeantVisitor()); -// Hello sergeant -// Hello sergeant commander.accept(new CommanderVisitor()); -// Good to see you commander +``` + +Program output: + +``` +Greetings soldier +Greetings soldier +Greetings soldier +Greetings soldier +Greetings soldier +Greetings soldier +Hello sergeant +Hello sergeant +Good to see you commander ``` ## Class diagram + ![alt text](./etc/visitor_1.png "Visitor") ## Applicability + Use the Visitor pattern when -* 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 -* 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 -* 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 +* 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. +* 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. +* 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. ## Real world examples From ef43af3b2372026214512fa486c758ce98721567 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Tue, 18 Aug 2020 16:42:02 +0000 Subject: [PATCH 14/18] docs: update README.md [skip ci] --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 36094b1db..225f14709 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ [![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) [![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) -[![All Contributors](https://img.shields.io/badge/all_contributors-124-orange.svg?style=flat-square)](#contributors-) +[![All Contributors](https://img.shields.io/badge/all_contributors-125-orange.svg?style=flat-square)](#contributors-) # Introduction @@ -254,6 +254,9 @@ This project is licensed under the terms of the MIT license.
xdvrx1

👀 🤔
Subhrodip Mohanta

💻 + +
Bethan Palmer

💻 + From 6c7715ace6b15cf010a4540b862d2b961c6e91c9 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Tue, 18 Aug 2020 16:42:03 +0000 Subject: [PATCH 15/18] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index 6ea5a5de6..712ae41c2 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -1130,6 +1130,15 @@ "contributions": [ "code" ] + }, + { + "login": "nahteb", + "name": "Bethan Palmer", + "avatar_url": "https://avatars3.githubusercontent.com/u/13121570?v=4", + "profile": "https://github.com/nahteb", + "contributions": [ + "code" + ] } ], "contributorsPerLine": 4, From 06f20570b637dd1c432b27b2ab8e7e041eb2754c Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Tue, 18 Aug 2020 16:45:37 +0000 Subject: [PATCH 16/18] docs: update README.md [skip ci] --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 36094b1db..91db25047 100644 --- a/README.md +++ b/README.md @@ -252,7 +252,7 @@ This project is licensed under the terms of the MIT license.
Ashish Trivedi

💻
洪月阳

💻
xdvrx1

👀 🤔 -
Subhrodip Mohanta

💻 +
Subhrodip Mohanta

💻 👀 From 31881f500dd6442c1b0e6413fb931d47b953d5aa Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Tue, 18 Aug 2020 16:45:38 +0000 Subject: [PATCH 17/18] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.all-contributorsrc b/.all-contributorsrc index 6ea5a5de6..8894929f7 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -1128,7 +1128,8 @@ "avatar_url": "https://avatars0.githubusercontent.com/u/13291222?v=4", "profile": "http://subho.xyz", "contributions": [ - "code" + "code", + "review" ] } ], From 847585334c4edea23aa675cc6b18c40db14982e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ilkka=20Sepp=C3=A4l=C3=A4?= Date: Tue, 18 Aug 2020 20:07:47 +0300 Subject: [PATCH 18/18] Update README.md --- unit-of-work/README.md | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/unit-of-work/README.md b/unit-of-work/README.md index 590f718d3..01aa8e5d7 100644 --- a/unit-of-work/README.md +++ b/unit-of-work/README.md @@ -11,21 +11,27 @@ tags: --- ## Intent -When a business transaction is completed, all the the updates are sent as one big unit of work to be persisted -in one go to minimize database round-trips. + +When a business transaction is completed, all the the updates are sent as one big unit of work to be +persisted in one go to minimize database round-trips. ## Explanation + Real world example -> 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. +> 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. In plain words -> Unit of Work merges many small database updates in single batch to optimize the number of round-trips. +> Unit of Work merges many small database updates in single batch to optimize the number of +> round-trips. [MartinFowler.com](https://martinfowler.com/eaaCatalog/unitOfWork.html) says -> Maintains a list of objects affected by a business transaction and coordinates the writing out of changes and the resolution of concurrency problems. +> Maintains a list of objects affected by a business transaction and coordinates the writing out of +> changes and the resolution of concurrency problems. **Programmatic Example** @@ -57,8 +63,9 @@ public class Student { } ``` -The essence of the implementation is the `StudentRepository` implementing the Unit of Work pattern. It maintains a map -of database operations (`context`) that need to be done and when `commit` is called it applies them in single batch. +The essence of the implementation is the `StudentRepository` implementing the Unit of Work pattern. +It maintains a map of database operations (`context`) that need to be done and when `commit` is +called it applies them in single batch. ```java public interface IUnitOfWork { @@ -160,7 +167,7 @@ public class StudentRepository implements IUnitOfWork { } ``` -Finally here's how we use the `StudentRepository` and `commit` the transaction. +Finally, here's how we use the `StudentRepository` and `commit` the transaction. ```java studentRepository.registerNew(ram); @@ -170,9 +177,11 @@ Finally here's how we use the `StudentRepository` and `commit` the transaction. ``` ## Class diagram + ![alt text](etc/unit-of-work.urm.png "unit-of-work") ## Applicability + Use the Unit Of Work pattern when * To optimize the time taken for database transactions.