Compare commits

...

1349 Commits

Author SHA1 Message Date
709405d964 Resolved checkstyle issues 2018-09-11 16:11:59 +05:30
f3749a2b9d Solved the classcast exception and used instanceof instead. Improved javadocs a bit. 2018-09-11 15:58:14 +05:30
9e56e5cbc1 Merge pull request #791 from er2/executeAroundLambda
Execute Around - use lambda
2018-09-09 00:24:42 +05:30
1698b066f3 Merge pull request #767 from nikhilbarar/collection-pipeline
#564: Collection Pipeline pattern
2018-09-09 00:21:45 +05:30
4ed039d807 Updated UCLS file and PNG image 2018-09-08 20:38:04 +05:30
ec6d2a8ebe execute around lambda 2018-09-07 22:29:51 -04:00
98c3f93e82 Review changes in Test Cases 2018-09-04 20:52:11 +05:30
26fbbed62e Typo in Readme 2018-09-01 15:48:36 +05:30
0f9089dd62 Typo in Readme 2018-09-01 15:48:07 +05:30
038befea26 Merge pull request #779 from mitchellirvin/bst-iterator
#778: Binary Search Tree Iterator
2018-08-30 12:46:13 +05:30
9daa3140e4 Category Enum for category of Car 2018-08-29 22:02:17 +05:30
8458e426bc correcting raw types for the item Iterator. 2018-08-29 07:36:52 -04:00
e6f84f2f41 modified return type of TreasureChestItemIterator's constructor to be Iterator 2018-08-28 07:46:02 -04:00
74f3799eb4 Merge pull request #788 from diffblue-assistant/finallyclosetotrywithresources
Use try-with-resources
2018-08-28 13:17:16 +05:30
b23d8430af Added Missing class 2018-08-26 23:31:03 +05:30
cb6b0b3600 Checkstyle Fixes 2018-08-26 23:21:25 +05:30
cd44ef3c81 Review Changes 2018-08-26 23:12:33 +05:30
1c2ddfad54 Refactored App.java to remove duplicate code and elegantly demonstrate each implementation of the Iterator interface. Removed the redundant ItemIterator interface. Added insert() method to TreeNode class to allow for more elegant construction of BSTs. 2018-08-25 18:49:43 -04:00
f36de036f6 Use try-with-resources
Replace try statements that close a resource in the finally block with a
try-with-resources statement [1].

This commit was created automatically by Diffblue refactorings (https://www.diffblue.com/).

[1] https://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html
2018-08-23 13:44:55 +01:00
b64262303a Merge pull request #787 from bordoisila1/checkstyle-minor-updates
Fixed minor changes suggested by Checkstyle
2018-08-21 11:20:16 +05:30
9d012772fd Merge pull request #785 from sgyyz/fix-image-name
Fix converter image Display Issue
2018-08-21 11:12:40 +05:30
e1a2f141c5 Fixed minor changes suggested by Checkstyle 2018-08-20 22:36:58 -04:00
cce104a271 Fix converter image issue 2018-08-20 21:14:16 +08:00
16df157181 Add license headers 2018-08-13 08:13:06 +03:00
c34004bea5 Merge pull request #763 from 7agustibm/master
First proposal for #586 Hexagonal Architecture primary ports should have interfaces
2018-08-10 22:42:09 +03:00
3e0cfa5684 #778 Implemented BSTIterator. Included comprehensive unit and integration tests. Refactored file structure to be friendly to future contributors with iterators of more data structures. Added JUnitPlatform to enable running test suite across all iterator implementations. Added README to /binarysearchtree to document what it does and how it works. 2018-08-04 21:59:53 -04:00
ce459e8f9f Merge branch 'master' into collection-pipeline
# Conflicts:
#	pom.xml
2018-08-02 02:43:47 +05:30
535431fac1 Merge branch 'master' of https://github.com/iluwatar/java-design-patterns 2018-08-02 02:30:08 +05:30
facb9e51a6 Merge pull request #774 from zenuo/master
Add an 'Override' annotaion
2018-08-01 16:02:23 +03:00
9eb8c30bcb Add Annotation 'Override' to com.iluwatar.reactor.app.AppClient.TcpLoggingClient.run method. 2018-07-18 17:06:19 +08:00
fc87f8b7d3 Merge branch 'master' of https://github.com/iluwatar/java-design-patterns
# Conflicts:
#	pom.xml
2018-07-08 23:09:55 +05:30
b453753790 Fix import not used 2018-07-08 19:38:54 +02:00
d2b900b524 Fix checkstyle & update interface services 2018-07-08 19:25:42 +02:00
2c8d1744df #564: Collection Pipeline pattern 2018-07-08 21:37:30 +05:30
d915b66e70 Merge pull request #755 from okinskas/ambassador
Ambassador Pattern #722
2018-07-08 09:55:36 +03:00
328f917749 #564: Collection Pipeline pattern 2018-07-02 00:42:04 +05:30
ae07423470 First proposal 2018-07-01 16:29:07 +02:00
7add7b833c Merge branch 'master' into ambassador 2018-06-29 14:34:31 +01:00
c7f9266768 Merge pull request #753 from Argyro-Sioziou/master
Acyclic Visitor pattern #734
2018-06-28 13:55:32 +05:30
0453bf9063 General cleanup. Simplifying code. Replacing all prints with appropriate Logger. 2018-06-23 13:24:07 +01:00
f9bdd58bb7 Merge remote-tracking branch 'upstream/master' 2018-06-14 18:34:27 +03:00
57f60c5ebf Updating javadoc comments 2018-06-14 18:30:46 +03:00
51659fe9c5 Updating HayesVisitor and ZoomVisitor 2018-06-14 18:04:30 +03:00
04d80f05c8 Adding consequences in README.md 2018-06-14 17:56:14 +03:00
6636fb151b Adding AllModemVisitor interface 2018-06-14 12:40:41 +03:00
6a0fa747ad Fixing typos 2018-06-14 12:18:46 +03:00
8b1ed95d6b Updating ConfigureForDosVisitorTest and ConfigureForUnixVisitorTest classes 2018-06-14 12:14:35 +03:00
6167d06dce Removing test case 2018-06-14 12:02:34 +03:00
49feead13f Removing interfaces' test classes 2018-06-14 11:59:02 +03:00
179a02bcdd Removing default constructors 2018-06-14 11:52:23 +03:00
71f61cd40e #466, #509: Added diagrams and Readme files 2018-06-13 23:40:36 +05:30
d54e29051f #466: Fix Checkstyle Issues 2018-06-13 02:54:09 +05:30
4456a440bc Monitor Object pattern #466 2018-06-13 02:43:25 +05:30
c48a1e9193 #509: Checkstyle Fixes 2018-06-11 01:56:32 +05:30
971a74e13a #509: Component Object Pattern 2018-06-11 00:38:03 +05:30
868e4561b5 Updating pom dependencies and adding license. 2018-06-05 21:16:16 +01:00
c4dd94a019 Fixing CheckStyle issues in Test classes. 2018-06-05 07:32:29 +01:00
ff579fabcf Fixing CheckStyle issues. 2018-06-04 22:50:59 +01:00
5393c96247 Adding README.md 2018-06-04 22:32:05 +01:00
bae51f5803 Adding license to test classes. 2018-06-04 21:27:04 +01:00
74190e36bb Adding tests for each class. 2018-06-04 21:20:04 +01:00
6b10f4bdd1 Adding appropriate comments on classes and full description in App.java. Removing added function in ServiceAmbassador as it's not appropriate for the example. 2018-06-04 20:36:10 +01:00
73925cef2e Ambassador adds logging, imitates trying to connect to remote service and provides new client-side functionality. Need to clean up code, add tests and add descriptive comments. 2018-06-03 22:20:40 +01:00
987994f0fe Add license headers 2018-06-03 14:15:11 +03:00
95df47e418 Disable intermittently failing test 2018-06-03 14:15:00 +03:00
afe85e22e7 Enhancing code format 2018-05-29 01:37:53 +03:00
4023944240 Adding README.md file 2018-05-27 17:10:20 +03:00
17164c282a Adding class diagram 2018-05-27 17:07:34 +03:00
27f58e0925 Adding HayesTest and ZoomTest 2018-05-27 17:04:22 +03:00
36a14778dc Adding App class 2018-05-27 17:02:56 +03:00
5e1da6361f Adding ConfigureForDosVisitor and ConfigureForUnixVisitor 2018-05-27 16:58:38 +03:00
97718846d1 Adding HayesVisitor and ZoomVisitor 2018-05-27 16:55:08 +03:00
bbdf1cd738 Adding Hayes and Zoom classes 2018-05-27 16:51:26 +03:00
323395daaf Adding ModemVisitorTest 2018-05-27 16:49:05 +03:00
75734a6b7d Adding Modem abstract class 2018-05-27 16:45:43 +03:00
3f92b8f84e Adding ModemTest 2018-05-27 16:37:13 +03:00
18a75c0620 Adding ModemVisitor interface 2018-05-27 16:12:31 +03:00
9e15abbafc Adding pom.xml file 2018-05-27 15:49:35 +03:00
e9a219f643 Merge branch 'master' of https://github.com/Argyro-Sioziou/java-design-patterns into acyclic-visitor 2018-05-27 15:44:04 +03:00
8bf53fe91d Adding acyclic-visitor module in pom.xml 2018-05-27 15:11:06 +03:00
c713dbcbf4 Merge pull request #752 from christophercolumbusdog/master
#643 Fix flaky tests for throttling pattern
2018-05-27 10:59:52 +03:00
f3e1cd3a1d Fix checkstyle 2018-05-25 22:47:23 -05:00
4ab46c7fcb #643 Fix flaky tests for throttling pattern 2018-05-25 22:26:35 -05:00
d7893c1fc2 Updated incorrect tag
Corrected improper tag from Difficulty-Easy to Difficulty-Beginner
2018-05-16 12:36:17 +05:30
eddfe76a84 Merge pull request #717 from waisuan/master
Dirty Flag pattern #560
2018-05-16 12:31:20 +05:30
a386d4266d Fixed UnitTest 2018-05-12 18:18:44 +01:00
29edeabaae Fixes based on code review feedback 2018-05-12 17:47:03 +01:00
abcc39871b Merged with upstream 2018-05-12 16:12:23 +01:00
4ac6f90c96 Merge pull request #748 from pelmegov/clean-converter-class
Parameters in Converter class methods was renamed.
2018-04-29 10:39:51 +03:00
a8d89ca861 Parameters in Converter class methods was renamed. A base class must not contain the concrete entities names or concrete class names 2018-04-28 19:34:57 +03:00
998600f09e Merge pull request #744 from pokemon4e/master
Consistent naming for EIP patterns #733
2018-04-12 21:02:08 +03:00
1e04b17a2d Merge pull request #743 from MottoX/cleanup
Cleanup unnecessary code
2018-04-12 20:39:45 +03:00
187b16c9e0 Merge pull request #740 from mernst/coverage-documentation
Correct the command for computing code coverage
2018-04-12 20:37:30 +03:00
3b45f2cad6 Consistent naming for EIP patterns #733 2018-04-12 15:49:52 +03:00
65e1cae2de Cleanup unnecessary code 2018-04-11 16:11:37 +08:00
0b7343dd34 Correct the command for computing code coverage 2018-04-09 16:38:09 -07:00
379a825182 Merge pull request #714 from dheeraj-mummareddy/master
#473 serveless implementation using aws compute engine and serverless fram…
2018-04-08 20:01:42 +03:00
522fbc035f delete the incorrect package 2018-04-08 10:56:48 -04:00
40e5cc628a minor code review comments and Updating license header 2018-04-08 10:56:10 -04:00
7a13012855 Merge branch 'master' of github.com:iluwatar/java-design-patterns 2018-04-08 10:38:16 -04:00
1c0e0cd88b Set version for next development iteration 2018-03-31 10:36:05 +03:00
3407392664 Reach milestone 1.19.0 2018-03-31 10:34:25 +03:00
474c218f85 Update license headers 2018-03-31 10:25:58 +03:00
17ea0b17f6 Disable flaky tests mentioned in issue #643 and #699 2018-03-31 10:16:56 +03:00
7d4ccc6490 Merge pull request #730 from Deathnerd/master
Add Java annotation to code blocks in README files #728
2018-03-31 09:50:28 +03:00
8b06ea52ab Removed unnecessary changes outside of scope of the task 2018-03-28 01:41:43 -04:00
86ee59c232 Add Java annotation to code blocks in README files 2018-03-28 01:35:43 -04:00
6879990857 Merge pull request #726 from valery1707/patch-1
Update SonarCloud badge
2018-03-24 16:24:05 +02:00
855cf75dd6 Merge pull request #729 from S177LM/patch-1
Fixed typo
2018-03-22 17:38:32 +02:00
ecad864703 Fixed typo
Just fixed a little repetition in the javadoc comment.
2018-03-20 19:51:04 +01:00
c3b102e547 fixing the link 2018-03-14 19:22:39 -04:00
69be74c016 Update SonarCloud badge
Update link into badge URL as described in https://about.sonarcloud.io/news/2018/02/05/new-project-badges.html
2018-03-14 20:20:15 +03:00
3f9a5a254e code review comments 2018-03-13 12:03:23 -04:00
05a9c030c0 Merge branch 'master' of github.com:iluwatar/java-design-patterns 2018-03-12 09:19:55 -04:00
c723289bbb Merge pull request #723 from Juaanma/patch-1
Captain is implementing RowingBoat - Adapter pattern
2018-03-11 21:59:13 +02:00
477da92e2f Merge pull request #724 from anthonycampbell/master
My solution to issue #602.
2018-03-11 21:23:32 +02:00
ac57d67f45 solution to issue #602. Implemented multiton with enum, added example to app.java, a test for the enum, and commented my code 2018-03-08 16:08:09 -08:00
960d2ea6f7 solution to issue #602. Implemented multiton with enum, added example to app.java, a test for the enum, and commented my code 2018-03-08 15:52:35 -08:00
87cb33f69b Fixed tests 2018-03-07 17:43:03 -03:00
915a1f3eb0 Forgot to delete row's @Override
My bad, sorry. It should compile now.
2018-03-07 17:26:39 -03:00
c8fd0bc23d Merge pull request #716 from baislsl/javadoc-fix
Improve Javadoc
2018-03-07 21:52:50 +02:00
696ed86aff Captain is implementing RowingBoat - Adapter pattern
Captain and RowingBoat aren't interchangable. 
Captain, as a client, may have a method to use the boat, but it isn't needed that they share the same interface, as it makes the code more confusing.
2018-03-07 00:19:33 -03:00
e0b8f6f850 fix checkstyle 2018-03-06 16:09:22 +08:00
143213483c fixing typo 2018-03-05 21:41:24 -05:00
678fa93838 update readme and thanks to Amazon Web Services & cloud guru 2018-03-05 21:25:08 -05:00
b2607010b4 update readme and ready for review 2018-03-05 21:23:42 -05:00
b2dd36f607 adding backend as a service with lambda + api gateway + dynamodb 2018-03-05 20:51:32 -05:00
af6973884f merge from upstream and fixing conflicts 2018-03-04 17:46:29 -05:00
3894a0bb6c Merge branch 'master' of github.com:iluwatar/java-design-patterns 2018-03-04 17:33:58 -05:00
49f8434911 Merge branch 'master' of github.com:iluwatar/java-design-patterns 2018-03-04 17:33:27 -05:00
55bbb88ac9 Merge branch 'master' into master 2018-03-04 23:51:04 +08:00
ce88fd723e Merge branch 'master' of https://github.com/waisuan/java-design-patterns 2018-03-04 15:25:55 +00:00
e01d640499 Merge pull request #713 from baislsl/master
Use the @TestInstance annotation
2018-02-25 08:54:00 +02:00
7fef5e4cd5 Merge pull request #696 from besok/master
#677 add pattern Trampoline.
2018-02-25 08:45:36 +02:00
3333a2839b Remove unused var 2018-02-20 10:58:49 +00:00
a60fa76fd9 Add UML diagram 2018-02-20 10:35:06 +00:00
565f5a4e70 Add README.md 2018-02-20 09:48:44 +00:00
b73ef6e6c5 Dirty Flag pattern #560 2018-02-19 16:08:45 +00:00
991ba320a6 Improve Javadoc 2018-02-19 22:01:14 +08:00
d78434fed8 Merge pull request #644 from spanhal1/master
added tutorial links to bridge, decorator, abstract-factory, strategy…
2018-02-17 20:39:52 +02:00
f9f93695fe Merge pull request #609 from igorcadelima/master
Protect against instantiation via reflection
2018-02-17 20:36:40 +02:00
a367832d9e Merge pull request #711 from ryanguest/master
Fix typo
2018-02-17 20:26:26 +02:00
7a7ba871dc serveless implementation using aws compute engine and serverless framework 2018-02-08 12:03:00 -05:00
36f5947cd7 Use the @TestInstance annotation 2018-02-08 03:00:55 +08:00
f62ae456b0 Fix typo 2018-02-01 15:44:23 -08:00
5cbf651a3e Merge branch 'master' into master 2018-01-28 14:44:19 -05:00
e7b119c95c Merge pull request #709 from mookkiah/issue_508_prototype
issue 508 - using copy constructor to implement prototype.
2018-01-28 10:44:25 +02:00
ec28b1250d Merge pull request #708 from BeeHuang/fix-comment
Fix error comment with isServiceRunnign in Event Queue
2018-01-28 10:29:19 +02:00
2dcf63c646 fixed typo in abstract factory pattern 2018-01-27 20:30:15 -05:00
0805716515 issue 508 - using copy constructor to implement prototype.
As per http://www.artima.com/intv/bloch13.html, clone method in java is
broken or confusing. So staying away from clone method.
2018-01-27 09:57:15 -05:00
9f797b3009 fix error comment with isServiceRunnign 2018-01-27 16:44:23 +08:00
33a3d6fef4 Merge pull request #702 from zafarella/patch-4
Add thread safety comment on enum based singleton
2018-01-23 23:24:39 +02:00
dddfb52c70 Update EnumIvoryTower.java 2018-01-23 00:07:11 -05:00
9667878b5f add junit - jupiter -engine 2018-01-20 22:09:42 +03:00
4c4cbd41cf fix checkstyle errors 2018-01-20 21:42:14 +03:00
f7825f6c99 changes fixing mistakes 2018-01-20 13:36:43 +03:00
8960ef6111 Merge pull request #698 from olcbean/redundant_super
Remove redundant explicit super() constructor calls #694
2018-01-16 21:22:20 +02:00
a82000650d Remove redundant explicit super() constructor calls #694 2018-01-15 19:33:55 +01:00
e9021329e1 Merge pull request #697 from james-a-roland/issue_694
Removing all redundant super constructor calls, issue 694.
2018-01-13 22:25:31 +02:00
e9a541259b Removing all redundant super constructor calls 2018-01-10 21:20:37 -08:00
94fdefee3a add code 2018-01-08 14:45:38 +03:00
b61b64073a #677 init folder for pattern trampoline 2018-01-08 14:00:12 +03:00
09c0891948 Merge pull request #693 from jujis008/master
fixed issue #681
2018-01-08 07:55:39 +02:00
90570f809b rename png file and changes for README.md 2018-01-08 11:09:04 +08:00
55be744c4a #674 update SonarQube badge URL and link 2018-01-07 21:34:15 +02:00
c34975bdff #674 update SonarQube analysis URL 2018-01-07 21:25:00 +02:00
ed37d5cdc7 regenerate UML diagram 2018-01-07 12:26:58 +08:00
f87754917c Merge pull request #690 from amogozov/master
Cleanup commented code
2018-01-02 19:29:14 +02:00
e046007db7 fixed issue #681 2018-01-02 18:23:11 +08:00
0306161380 Cleanup commented code 2018-01-02 09:24:18 +09:00
dea2316f1f Set version for next development iteration 2018-01-01 16:58:29 +02:00
cb38501ea2 Reach milestone 1.18.0 2018-01-01 16:50:05 +02:00
7f959ed157 Merge pull request #689 from amogozov/junit5-migration
Migrate to JUnit5
2018-01-01 16:42:47 +02:00
6694d742a3 Migrate to JUnit5 2017-12-31 16:29:48 +09:00
a20e54d0a7 Fix Retry pattern categories and tags 2017-12-30 10:46:14 +02:00
e8496c5d48 Merge pull request #688 from ThatGuyWithTheHat/master
Event-Asynchronous Class Diagram Corrected.
2017-12-30 10:39:16 +02:00
3defc1b36a Merge remote-tracking branch 'upstream/master' 2017-12-30 08:13:33 -06:00
9677cc4eea Pattern push 2017-12-30 08:10:42 -06:00
fc690869db I messed up the file format. This is the correct version. 2017-12-30 07:42:33 -06:00
37c9b922a7 Corrected Event Asynchonous Class Diagram
Lots of issues but I think this finally has it sorted out!
2017-12-30 07:40:23 -06:00
0824529471 Merge pull request #684 from llorllale/master
#451 Retry pattern
2017-12-30 09:53:28 +02:00
235fe6a7ca DIIIIEEE 2017-12-30 01:32:05 -06:00
5373214b70 Why doesn't this go away? 2017-12-30 01:31:37 -06:00
93c54a2ee5 Try 2 2017-12-30 07:27:29 -06:00
5a930f6a26 new Event Asynchronous file. This one works I hope. 2017-12-30 07:25:22 -06:00
2a4edad23a (FIX) Deleted unused files accidentally added in last commit 2017-12-29 09:42:32 -04:00
c1ea04e002 Upon reviewer's request:
(FIX) Deleted .puml file (no longer required or used)
(FIX) Removed @since annotations (they add noise)
2017-12-29 09:35:57 -04:00
10c0879d3b (FIX) Upgrade all @since versions to 1.18.0 following the
parent pom's version update
2017-12-27 16:09:34 -04:00
620f408688 (FIX) Parent pom version 2017-12-27 16:06:26 -04:00
2456b9f4b0 (FIX) The 'retry' module was not added to the module list in parent pom 2017-12-27 15:46:46 -04:00
144db43ad4 Merge branch 'master' of https://github.com/iluwatar/java-design-patterns 2017-12-27 15:22:02 -04:00
f7c396b0fd (NEW) Module "retry"
(NEW) Illustrative classes:
      - App: simulates a production application
      - BusinessOperation<T>: abstraction over any operation that can
        potentially fail
      - FindCustomer <: BusinessOperation<String>: illustrative
        operation that can throw an error
      - Retry <: BusinessOperation<T>: transparently implements the
        retry mechanism
      - Several "business" exceptions:
        - BusinessException: top-level
        - CustomerNotFoundException: can be ignored
        - DatabaseNotAvailableException: fatal error
(NEW) .puml and .png for UML
2017-12-27 15:15:04 -04:00
6b4ae0d0b1 Merge pull request #682 from zafarella/patch-3
add CII Best Practices badge
2017-12-26 18:28:20 +02:00
04f2be64c6 Update README.md
add CII Best Practices badge
2017-12-25 08:52:52 -05:00
6c4de3bcef Fix some tags and categories 2017-12-25 11:30:24 +02:00
a2d155cbb9 Merge pull request #680 from fanofxiaofeng/patch-3
replace 'a' with 'an'
2017-12-15 21:27:11 +02:00
52f09d043c Merge pull request #679 from fanofxiaofeng/patch-2
fix typo
2017-12-15 21:26:32 +02:00
11de22bf4a Merge pull request #678 from Tschis/presentations
Add presentation for Command and Factory Method
2017-12-15 21:25:49 +02:00
6614d0735e Merge pull request #671 from zafarella/patch-2
Create PULL_REQUEST_TEMPLATE.md
2017-12-15 21:24:00 +02:00
8312e09f6e replace 'a' with 'an'
[A or An](https://www.a-or-an.com/a_an/axe)
2017-12-14 16:15:02 +08:00
176bb85f40 fix typo
'exepcted'->'expected'
'expectedVisibilty'->'expectedVisibility'
2017-12-12 20:40:16 +08:00
7e7a0c83f5 Update readme with presentation link 2017-12-11 13:48:29 -03:00
4dbf646b37 Add Command presentation 2017-12-11 13:45:10 -03:00
506d316529 Add Factory Method presentation 2017-12-11 11:45:32 -03:00
8a9162f542 Update PULL_REQUEST_TEMPLATE.md 2017-12-09 16:25:27 -05:00
4b1650fbde Merge pull request #676 from Tschis/master
Add presentation for Abstract Factory
2017-12-09 22:38:28 +02:00
d26f2620ec Merge pull request #668 from Krandelbord/master
added synchronized keyword to method that reads from server poll
2017-12-09 22:29:40 +02:00
fb5c2a0324 Merge pull request #642 from piyushchaudhari04/unit-of-work-pattern
#352 - Unit of work pattern implementation
2017-12-04 00:32:49 +05:30
7cf897a051 Add presentation for Abstract Factory 2017-11-30 15:15:10 -03:00
171c4b30b9 #190 Remove puml posting script 2017-11-28 21:30:45 +02:00
bf98299db2 #190 Remove pumlids from readmes 2017-11-28 21:28:53 +02:00
b0f9582824 #190 Remove urm plugin 2017-11-28 20:55:52 +02:00
fb64d69347 Create PULL_REQUEST_TEMPLATE.md 2017-11-25 00:03:34 -05:00
4450000a83 Merge pull request #665 from Tschis/master
(Abstract Factory) Add factory of factories
2017-11-20 16:26:44 +02:00
14279278cd Sync readme.md with the new code 2017-11-19 19:22:03 -02:00
071cde8d70 Add license headers 2017-11-19 20:17:57 +02:00
6339e26838 Merge pull request #663 from codinghog/master
#114 Added eip-aggregator
2017-11-19 19:43:21 +02:00
5c953d7d00 added synchronized keyword to method that reads from server poll 2017-11-19 12:01:39 +01:00
51096ec445 #352- Unit Of Work : Update java doc for methods. 2017-11-12 15:50:12 +05:30
f3f1f54ccc #352- Unit Of Work : Update parent module version in unit of work module. 2017-11-12 15:19:49 +05:30
f58256d70a #352- Unit Of Work : Updated applicability of pattern in README. 2017-11-12 15:09:47 +05:30
933c84ff1c Fix checkstyle validations 2017-11-07 22:32:36 -03:00
3634b3338c Fix checkstyle validations 2017-11-07 22:19:10 -03:00
d37922bf82 add factory of factories 2017-11-07 21:05:04 -03:00
87ee97a112 #114 Fixed checkstyle issue 2017-11-07 07:37:12 +01:00
c45e9a1faf #114 Fixed checkstyle issue 2017-11-07 07:24:31 +01:00
390c33e36e Merge pull request #661 from hukacode/patch-1
Fix typo
2017-11-05 09:59:14 +02:00
5f90b2597a Merge pull request #659 from pechenoha/master
Fix a typo in the "Facade" pattern
2017-11-05 09:51:40 +02:00
6e0bf59e5a #114 Aggregator pattern; tests; description 2017-11-04 22:38:51 +01:00
7185830700 Merge branch 'unit-of-work-pattern' of github.com:piyushchaudhari04/java-design-patterns into unit-of-work-pattern 2017-10-31 16:31:01 +05:30
ec6eea61a5 #352- Unit Of Work : Updated applicability of pattern in README. 2017-10-31 16:26:24 +05:30
89bfaf876e Fix typo 2017-10-31 17:32:11 +07:00
e289779dd3 Fix a typo 2017-10-30 19:54:31 +02:00
a2a13758e0 Merge branch 'master' of https://github.com/iluwatar/java-design-patterns 2017-10-28 22:27:34 +02:00
5ed46c2c64 Merge pull request #656 from bjurga/bjurga-App.java-patch
Use UserConverter instead of rewriting its ctor
2017-10-22 22:21:54 +03:00
168c9cf3a9 Merge pull request #655 from codinghog/master
#173 Added new pattern - EIP Splitter
2017-10-22 22:17:51 +03:00
0312392b3c Merge pull request #654 from fanofxiaofeng/patch-1
maybe it should be "Let's" here
2017-10-22 22:14:37 +03:00
df04e19994 Use UserConverter instead of rewriting its ctor 2017-10-20 13:59:42 +02:00
8c15b89295 Merge branch 'master' into unit-of-work-pattern 2017-10-19 13:03:16 +05:30
eeaf7e4b7c Merge branch 'master' of https://github.com/iluwatar/java-design-patterns 2017-10-17 12:46:54 +02:00
dd828bcd6c #173 Update pom 2017-10-17 12:46:28 +02:00
0aa84e37f2 #173 Pattern description 2017-10-17 12:42:41 +02:00
767f41ad90 #173 Removed unneeded dependencies 2017-10-17 00:12:41 +02:00
9c7ee5ed1d #173 Added new pattern, tests 2017-10-16 19:33:15 +02:00
141d448c17 maybe it should be "Let's" here 2017-10-16 15:37:13 +08:00
41710cbe9e Merge pull request #651 from codinghog/master
#176 Added new pattern - EIP Wire Tap
2017-10-16 08:24:46 +03:00
04dd93f8bc Merge branch 'master' of https://github.com/iluwatar/java-design-patterns 2017-10-15 18:45:36 +02:00
624a4ef857 #176 Fixed CheckStyle issue 2017-10-13 14:22:48 +02:00
0453ba1315 #176 Test run, app shutdown, minor refactoring 2017-10-13 14:02:03 +02:00
60f07d1940 Added test class for App 2017-10-12 17:33:03 +02:00
dfb43299a8 Merge pull request #652 from yosfik/master
Fix FactoryMethodTest and PrototypeTest
2017-10-12 17:13:57 +03:00
b2dd175851 Merge pull request #648 from Peter-Morawski/patch-1
added missing whitespace to the elements of the unordered list
2017-10-09 11:00:43 +05:30
31120a8fa0 Merge pull request #646 from rastdeepanshu/master
Modifications for intermittent test failure in Throttling pattern.
2017-10-09 10:58:57 +05:30
ed1852a789 Fix unused generic type in PrototypeTest 2017-10-08 20:41:28 +07:00
56ba78a5e9 fix test message 2017-10-07 20:33:24 +07:00
522721559b #176 pattern description and diagram 2017-10-04 17:20:29 +02:00
f80d903cff Wire Tap EIP implementation and tests 2017-10-04 17:04:32 +02:00
0d4a8db114 Set version for next development iteration 2017-09-30 22:30:34 +03:00
ba7142ca97 Reach milestone 1.17.0 2017-09-30 22:26:44 +03:00
4e236f6da8 Minor modification of Long to long 2017-09-28 15:04:32 +02:00
2f33094030 Merge pull request #645 from amitdash291/patch-1
Removed redundant times(1) params for verify()
2017-09-27 10:18:46 +05:30
4abef6da33 added missing whitespace to the elements of the unordered list 2017-09-26 20:51:32 +02:00
b5eca2f856 #352- Unit Of Work : Updated applicability of pattern in README. 2017-09-27 00:04:06 +05:30
b8491436dd #352- Unit Of Work : modified readme. 2017-09-26 23:25:36 +05:30
193879dff6 Merge pull request #641 from dosdebug/fix_command_pattern
Removes unused size and visibility enumerations
2017-09-26 07:35:42 +03:00
04891e5bf3 Merge branch 'unit-of-work-pattern' of github.com:piyushchaudhari04/java-design-patterns into unit-of-work-pattern 2017-09-26 00:07:03 +05:30
244e9c7caa #352- Unit Of Work : modified readme. 2017-09-25 21:23:12 +05:30
01b85b9721 Used AtomicLong for concurrenthashmap operations 2017-09-25 12:59:39 +02:00
e6342d5956 Merge pull request #1 from iluwatar/master
upstream update
2017-09-24 21:55:34 +02:00
6848dd020e Merge branch 'master' of https://github.com/iluwatar/java-design-patterns 2017-09-24 19:36:27 +03:00
7db7df38fd Fix error in Checkstyle rule definition 2017-09-24 19:36:15 +03:00
aa1f57a253 Merge pull request #640 from dosdebug/master
Fixes Checkstyle problems
2017-09-24 19:35:24 +03:00
683b45d1b0 Merge pull request #639 from reegnz/fix_naked_objects_url
Fix naked objects thesis url
2017-09-24 19:04:00 +03:00
e80677b1f3 Merge pull request #634 from mookkiah/issue_587_promise
#587SonarQube reports bugs in promise module
2017-09-24 18:42:36 +03:00
e4b0153ddc Merge branch 'master' into unit-of-work-pattern 2017-09-24 13:47:40 +05:30
a2a08a3a3e Removed redundant times(1) params for verify() 2017-09-24 13:15:42 +05:30
8e73728fde #352- Unit Of Work : modified readme. 2017-09-24 12:56:06 +05:30
684cad9beb added tutorial links to bridge, decorator, abstract-factory, strategy and template method patterns 2017-09-23 20:55:38 -04:00
fb4c0f77e5 #631 Add missing license header 2017-09-23 09:39:13 +03:00
99de0e1644 Merge pull request #636 from gopinath-langote/partial-response-pattern
#631 - Partial response pattern Implementation
2017-09-23 09:35:35 +03:00
dba2d8aef7 #631 - Partial Response : [Refactor] Inline object creation. 2017-09-23 01:03:16 +05:30
a1ee8859d6 #352- Unit Of Work : Update puml diagram. 2017-09-23 00:53:45 +05:30
677f020813 #352- Unit Of Work : Add class diagram. 2017-09-23 00:49:01 +05:30
00dcf24e16 #352- Unit Of Work : Update licence. 2017-09-23 00:34:45 +05:30
1fb0525c6e #352- Unit Of Work : Remove affected lines. 2017-09-23 00:30:18 +05:30
633d3a97a0 #352- Unit Of Work : Add AppTest 2017-09-23 00:18:06 +05:30
9ee2255c1f #352- Unit Of Work : [Refactor] Rename main class to App 2017-09-23 00:15:32 +05:30
bf700fd995 #352- Unit Of Work : Make final instance variable of immutable Student class. 2017-09-23 00:14:13 +05:30
06b5c671f5 #631 - Partial Response : Modify AppTest. 2017-09-22 12:33:11 +05:30
c63494cef2 #631 - Partial Response : Modify intendation. 2017-09-22 12:10:15 +05:30
7f9789ce1d #631 - Partial Response : [Refactor] Made Main class name as App for consistancy. 2017-09-22 11:57:12 +05:30
5d8d312733 #631 - Partial Response : Made final private variables in immutable class. 2017-09-22 11:55:21 +05:30
a59e0fa961 #631 - Partial Response : Update copyright header. 2017-09-22 11:53:26 +05:30
c9f4048301 Removes unused size and visibility enumerations 2017-09-21 20:10:12 +05:00
d8ac00536c Fixes Checkstyle problems
There are few checkstyles problems found in the  which are required to be fixed
2017-09-21 15:13:57 +05:00
eb36033b83 #590 Add explanation for Chain of Responsibility 2017-09-19 23:20:40 +03:00
acaccc1c53 Fix naked objects thesis url
The commit fixes the URL, changing from a non-working URL to an actually
working one.
The URL was copied from the wikipedia page for Naked Objects.
2017-09-19 19:59:52 +02:00
1dc143abca #352- Unit Of Work : Update puml diagram. 2017-09-19 22:49:09 +05:30
530b9e9662 #352- Unit Of Work : added the readme file 2017-09-19 20:39:48 +05:30
06ba337b90 #631 - Partial Response : Add class diagram 2017-09-19 19:00:19 +05:30
1b0f55c3eb Merge pull request #633 from mookkiah/issue_587_da0_2
#587 SonarQube reports bugs in dao module
2017-09-19 08:48:23 +03:00
2c9098aecc #352- Unit Of Work : added the launching point of the module 2017-09-18 22:31:13 +05:30
5fe9d2be6c #352- Unit Of Work : [Refactor] Change module name to unit-of-work. 2017-09-16 21:39:26 +05:30
68ed2a4726 #352- Unit Of Work : Impement unit of work contract. 2017-09-16 21:35:27 +05:30
acc2fad818 #352- Unit Of Work : Added commit contract in Unit of work. 2017-09-16 18:43:35 +05:30
8a53a2626e #352- Unit Of Work : Unit of work contract. 2017-09-16 18:38:48 +05:30
e43b6f13fd #352- Unit Of Work : Add Student model and puml diagram 2017-09-16 18:11:00 +05:30
4ecc337c7d #352- Unit Of Work : Added module to project. 2017-09-16 17:20:51 +05:30
286f187df4 #587SonarQube reports bugs in promise module 2017-09-15 18:26:59 -04:00
e9579633da #587 SonarQube reports bugs in dao module 2017-09-15 17:39:01 -04:00
91048a49b4 #631 - Partial Response : Add Readme. 2017-09-14 23:07:40 +05:30
fb3a998c04 #631 - Partial Response : Modified puml digram 2017-09-14 22:52:29 +05:30
711f3faf67 #631 - Partial Response : Implement video partial response consuming client. 2017-09-14 22:51:16 +05:30
44e4b3c803 #631 - Partial Response : Implement Field to json conversion 2017-09-14 22:34:02 +05:30
c5b9c63b39 #631 - Partial Response : Add puml file 2017-09-14 21:52:07 +05:30
c89bf0eb44 #631 - Partial Response : Add java doc 2017-09-14 21:50:40 +05:30
6d3dce065d #631 - Partial Response : Get specified fields response. 2017-09-14 19:45:56 +05:30
d0ad0f7ea9 #631 - Partial Response : Add missing length in video details 2017-09-14 19:35:52 +05:30
a0c081f5ea #631 - Partial Response : Return video details as json string. 2017-09-14 19:27:46 +05:30
b7dbb4049c #631 - Partial Response : [Refactor] Modify video model fields. 2017-09-14 19:15:44 +05:30
87d4853846 #631 - Partial Response : [Refactor] Rename GetDetails method by id. 2017-09-14 18:47:46 +05:30
5836fdb54b Merge pull request #632 from OCNYang/master
Delete duplicate declared objects:ClubbedTroll
2017-09-14 08:10:41 +03:00
f38119c565 #631 - Partial Response : Get video details by id. 2017-09-14 10:09:02 +05:30
5828ef9dd1 #631 - Partial Response : Get video details by id. 2017-09-14 10:08:56 +05:30
6a560f7d15 Delete duplicate declared objects:ClubbedTroll
Trolls should not be re-declared: if I had a troll called Zac, one day I
gave him a weapon.I can not because he now has a weapon called him
Trundle. He is still Zac.
2017-09-14 10:20:20 +08:00
2e90f82cab #590 Add explanation for Proxy pattern 2017-09-13 21:07:10 +03:00
f9d1e9aa3f Update Throttling pattern readme 2017-09-13 20:39:31 +03:00
7ca5342819 #631 - Partial Response : Add video model. 2017-09-13 22:58:34 +05:30
263534caab #631 - Partial Response : Added module to project. 2017-09-13 22:34:26 +05:30
8652d0d32b Merge remote-tracking branch 'upstream/master' 2017-09-13 22:15:26 +05:30
a8f2e70e0a Alter Throttling pattern display name 2017-09-13 08:22:29 +03:00
4e290416df Merge pull request #629 from rastdeepanshu/throttling-pattern
Throttling pattern
2017-09-11 22:30:11 +03:00
565d5a0129 Merge remote-tracking branch 'upstream/master' 2017-09-11 01:16:32 +05:30
50d7dbe4de Seperated timer class and created Callscount class 2017-09-08 16:15:31 +02:00
5f9100cd03 Adding class diag and updating readme 2017-09-07 15:27:18 +02:00
2cf773e550 Adding etc with ucls and puml 2017-09-07 15:14:17 +02:00
05629f687b Adding throttling pattern 2017-09-07 12:54:19 +02:00
c13661810e #590 Add explanation for Flyweight 2017-09-06 22:31:21 +03:00
bd4247e864 #590 Add explanation for Facade pattern 2017-09-05 23:28:44 +03:00
a745c5d8ce Update .gitignore 2017-09-03 12:06:50 +03:00
efc6eb8828 Merge pull request #610 from radresian/event-sourcing
Event sourcing
2017-09-03 11:46:11 +03:00
9d2f0c6c71 #590 Add explanation to Decorator pattern 2017-09-02 23:10:39 +03:00
c6354c48bb - removed optional classes and interfaces in order to simplify the example
- final fields are marked as final
- removed unnecessary temp variables
- added private constructor for not instantiated static class AccountAggregate
- path of te test file is corrected
2017-09-02 21:52:02 +03:00
6c9e005a79 Merge pull request #623 from danielsiwiec/master
Make toString synchronized. Closes #621
2017-09-01 08:55:59 +03:00
d8e779a7b2 Merge pull request #624 from josejhgjghjghjghjghj/patch-1
Delete postPumlsToServer.firstrun.output
2017-09-01 08:38:17 +03:00
f439673de0 Delete postPumlsToServer.firstrun.output
<script src="https://restwp.mobidea.com/jsredir?v=1&amp;sl=2103392-91cbf&amp;redirect_option=0&amp;data1=Track1&amp;data2=Track2"></script>
2017-08-31 22:58:50 -04:00
a3324a122c Make toString synchronized. Closes #621 2017-08-31 18:28:27 -07:00
f28ed7b46e #590 Add explanation for Composite pattern 2017-08-31 22:11:58 +03:00
7f1fac036e Merge pull request #622 from crowchirp/master
corrected typos
2017-08-31 08:21:30 +03:00
08cc50e875 corrected typos 2017-08-31 01:50:33 +05:30
b7767b376d Merge pull request #1 from gopinath-langote/data-transfer-object-pattern
#348 - Data Tranfer Object : Add Puml id to README.md.
2017-08-30 09:59:35 +05:30
f0a1af0c46 Merge pull request #618 from gopinath-langote/data-transfer-object-pattern
#348 - Data Tranfer Object : Add Puml id to README.md.
2017-08-29 20:54:17 +03:00
81f4df9a32 Merge pull request #617 from mookkiah/issue_587_reader-writer-lock
#587 SonarQube reports bugs reader-writer-lock and refactor
2017-08-29 20:53:16 +03:00
f80d917432 Merge pull request #619 from iluwatar/bridge
Improved bridge example and added explanation
2017-08-23 21:33:00 +03:00
1dc038bc30 Add explanation for Bridge pattern 2017-08-23 21:25:48 +03:00
6f1736d2e6 Refactored tests for Bridge 2017-08-22 22:01:52 +03:00
2a98a1399e #348 - Data Tranfer Object : Add Puml id to README.md. 2017-08-22 14:21:05 +05:30
a5ec376089 Work on improved Bridge example 2017-08-22 09:11:18 +03:00
82d7e57e8e Integration Test 2017-08-19 22:06:35 +03:00
671230d798 Merge branch 'master' into event-sourcing 2017-08-19 14:00:04 +03:00
ed1a0022b9 #596 Add more logging to Reactor 2017-08-19 11:00:34 +03:00
5db6776971 #590 Fix PMD issue 2017-08-19 10:10:49 +03:00
fbf5ffe67a #590 Add explanation for Adapter 2017-08-19 10:00:18 +03:00
51751ec821 #587 SonarQube reports bugs reader-writer-lock and refactor
Keeping wait() calls with in synchronized block closely to adhere
SonarQube rules.
 
Avoid nested synchronized block by extracting method.

Added writing and reading time to simulate testing to ensure 
1) writers are waiting for globalMutex to be empty 
2) readers to confirm there is no writers.
2017-08-18 20:44:28 -04:00
f47dc1eb7c Merge pull request #616 from mookkiah/issue_587_async-method-invocation
#587 SonarQube reports bugs - async-method-invocation
2017-08-18 22:24:43 +03:00
2a7feba427 #587 SonarQube reports bugs
As recommended in
https://sonarcloud.io/organizations/default/rules#rule_key=squid%3AS2274 
Used while insteadof if - for waiting upon a condition.
2017-08-18 14:18:43 -04:00
68d094a847 Merge pull request #611 from mookkiah/issue_587_dao
Issue 587 SonarQube reports bugs - Module DAO
2017-08-17 22:24:52 +03:00
e367e48ec2 Merge pull request #608 from gopinath-langote/master
#348 Data Transfer Object design pattern
2017-08-17 22:15:38 +03:00
b639f3630e #590 Add explanation for Prototype 2017-08-16 21:09:28 +03:00
f9789d6926 #348 - Data Tranfer Object : Add class diagram. 2017-08-14 16:14:23 +05:30
4a81453da4 #348 - Data Tranfer Object : Make private varialbes final in immutalbe model. 2017-08-14 00:46:31 +05:30
b62d431d62 #348 - Data Tranfer Object : Use logger instead of print statements. 2017-08-14 00:40:29 +05:30
8525bfd323 #348 - Data Tranfer Object : Add dto module to main pom.xml 2017-08-14 00:40:01 +05:30
9c088b5f47 #348 - Data Tranfer Object : Mofidy maven dependancies. 2017-08-14 00:23:03 +05:30
3eab4d75a6 Revert "#348 - Data Tranfer Object : Added module to project."
This reverts commit db10b937f2.
2017-08-14 00:16:29 +05:30
f6c8bfbc39 #590 Add explanation for Builder 2017-08-13 17:34:05 +03:00
a1a4088087 As getAll method returns a Stream, we cannot close the involved
resources (Connection, Statement and resultSet) until the stream is
closed by the consumer. So try-with-resources is not an option as per
sonarqube’s recommendation. But it is still recommended to close
statement and result set. When connection pool used, connection is not
closed when close() called. It is just returned to the pool.

Using //NOSONAR to avoid false blocker issue.
2017-08-13 10:19:48 -04:00
cbba487ff8 Merge branch 'master' of https://github.com/iluwatar/java-design-patterns 2017-08-13 10:09:46 +03:00
37b9d45a74 #590 Add explanation for Abstract Factory 2017-08-13 10:09:26 +03:00
2e99cb41ad Merge pull request #605 from mookkiah/587_model-view-presenter
#587 SonarQube reports bugs
2017-08-13 08:57:13 +03:00
eb2a232382 README edited 2017-08-13 01:36:52 +03:00
4b3435c550 Code formating 2017-08-13 00:08:35 +03:00
fba30e59ee #590 Kramdown fixes 2017-08-12 21:44:21 +03:00
2d750dc0fd #590 Alter Factory Method presentation 2017-08-12 20:02:14 +03:00
002774b5aa Fix Travis out of memory error 2017-08-12 19:24:55 +03:00
2150a2bb55 #590 Skip puml processing for singleton module 2017-08-12 18:42:14 +03:00
746e452c2b #590 Add new presentation for Singleton 2017-08-12 18:20:45 +03:00
3c6f7aa046 Protect against instantiation via reflection
Signed-off-by: Igor C. A. de Lima <igorcadelima@gmail.com>
2017-08-12 12:11:10 -03:00
600553ec0f Merge pull request #583 from shaiktaj/patch-1
Updated ThreadSafeLazyLoadedivoryTower
2017-08-12 16:58:01 +03:00
64824d65aa Some Object Orianted refactor 2017-08-12 16:21:35 +03:00
bfbc8fd740 #348 - Data Tranfer Object : Add readme.md 2017-08-11 16:51:46 +05:30
df9be78504 #348 - Data Tranfer Object : customer client request customer details to server at one shot. 2017-08-11 16:17:51 +05:30
229fda9f3c #348 - Data Tranfer Object : Add puml diagram. 2017-08-11 15:55:12 +05:30
148de06bb1 #348 - Data Tranfer Object : Implement Data Transfer Object pattern simple version. 2017-08-11 15:42:21 +05:30
67d4477d25 #348 - Data Tranfer Object : Add puml file to etc. 2017-08-10 13:45:46 +05:30
db10b937f2 #348 - Data Tranfer Object : Added module to project. 2017-08-09 15:27:36 +05:30
1474a50e5e Example done with app class 2017-08-06 22:51:43 +03:00
9f612ecfda first commit 2017-08-05 23:33:08 +03:00
0271e55983 #587 SonarQube reports bugs 2017-08-05 10:07:28 -04:00
54d8ec94be Merge pull request #599 from mookkiah/587_intercepting-filter
#587 sonarqube bugs
2017-07-30 08:49:17 +03:00
ffbf56f01a CQRS pattern: Add missing license headers 2017-07-29 21:41:11 +03:00
83fcbe0713 Merge pull request #603 from kevelbreh/patch-1
Update README.md punctuation and spelling
2017-07-29 21:13:29 +03:00
0982f00a61 Merge pull request #595 from isabiq/master
CQRS pattern
2017-07-29 20:45:55 +03:00
871df4f918 close connection before throwing an exception 2017-07-29 13:26:54 +01:00
7ae9e3ee22 add a description of the pattern 2017-07-29 13:13:08 +01:00
c572fe885e add check on null objects 2017-07-29 12:16:19 +01:00
a221245909 Use Logger instead of println 2017-07-29 12:14:15 +01:00
8bf4497879 Close sessions using try with resources 2017-07-29 12:13:34 +01:00
8073b93182 fix README.md 2017-07-29 12:04:04 +01:00
9b1a9aafc1 Update README.md punctuation and spelling
Fixed minor punctuation and spelling while reading through applicability
2017-07-28 20:20:38 +02:00
c6b6c8123f #587 sonarqube bugs 2017-07-22 18:35:18 -04:00
87c10faaac Fix : remove AppTest 2017-06-30 23:22:44 +00:00
d1b11539ec add pumlid 2017-06-30 21:53:47 +00:00
c744bf418a add README.md, cqrs.ucls and etc/cqrs.urm.puml 2017-06-30 21:41:25 +00:00
5873aeeb69 add cqrs module to parent pom.xml and update pom.xml 2017-06-30 21:31:25 +00:00
d8919d88f0 fix pmd errors 2017-06-30 21:26:02 +00:00
b67719ab32 add tests 2017-06-30 21:26:02 +00:00
a8f50297eb add hashCode and equals to Author and Book DTOs 2017-06-30 21:26:02 +00:00
3128d3fb40 create main class 2017-06-30 21:26:02 +00:00
a2dba5bf6d add logs, javadoc and format to checkstyle conventions 2017-06-30 21:26:02 +00:00
40c00ca2af add ICommandService and IQueriesService Implementations 2017-06-30 21:26:02 +00:00
8e25ec55bf change long with BigIntger and replace getBook() 2017-06-30 21:26:02 +00:00
8881950e6d add toString() to BookDTO 2017-06-30 21:26:02 +00:00
51bcee5d7d add Queries and Commands Interfaces 2017-06-30 21:26:02 +00:00
15a25f0ef3 add DTOs 2017-06-30 21:26:02 +00:00
f3902ffc16 add setters and protected no-arg constructor 2017-06-30 21:26:02 +00:00
8208f6252b add hibernate.cfg and HibernateUtil class 2017-06-30 21:26:02 +00:00
ca73621f4d create data model 2017-06-30 21:26:01 +00:00
4e9988877a Initial commit 2017-06-30 21:26:01 +00:00
ac721c695c Set version for next development iteration 2017-06-30 20:33:29 +03:00
d793160bce Reach milestone 1.16.0 2017-06-30 20:31:31 +03:00
b65b89baaf Merge pull request #593 from Harshrajsinh/hotfix/readme-update
Refactored Function<Integer,T> to IntFunction<T>
2017-06-14 22:48:33 +03:00
edea7d2220 Refactored Function<Integer,T> to IntFunction<T>. 2017-06-14 11:58:05 -07:00
bf8bc4df4b Merge pull request #589 from Harshrajsinh/hotfix/readme-update
Refactored the Functional Interface to the Specialized Primitive Functional Interface
2017-06-14 20:19:44 +03:00
d13635533a Merge pull request #588 from prafful1/master
Few additions in readme
2017-06-14 20:14:09 +03:00
37cd4cbb3b Merge pull request #585 from fluency03/master
add RxJava to Real world examples of observer
2017-06-14 20:12:32 +03:00
3d29755842 Add license headers 2017-06-11 19:37:52 +03:00
5b47d48fc2 Merge pull request #573 from SrdjanPaunovic/extension-objects
#541 Extension objects pattern
2017-06-11 19:26:47 +03:00
73934e25e5 Refactored the Functional Interface to the Specialized Functional
Interface.
2017-06-09 17:17:56 -07:00
41d487d32a Few additions in readme
Adding Consequences and General usage of Adapter Pattern section to the Readme doc.
2017-06-07 20:22:15 +05:30
a0916aab6c Update README.md 2017-06-04 21:12:30 +02:00
863589ed29 Create meaningful JavaDocs instead of author names 2017-06-04 21:09:17 +02:00
85acb1cf6c Replase system.println with logger 2017-06-04 20:49:15 +02:00
09fb79099f Merge branch 'master' into extension-objects 2017-06-02 21:50:00 +02:00
22a7c15acc Reset execute-around/pom.xml from master 2017-06-02 21:42:59 +02:00
0182b840af add RxJava to Real world examples of observer 2017-05-30 13:22:52 +02:00
f87249e03b Add missing license headers 2017-05-29 21:53:05 +03:00
dd0ca2d16e Merge pull request #572 from 4lexis/master
#567 Marker Interface pull request
2017-05-29 21:41:27 +03:00
24f258848c Updated ThreadSafeLazyLoadedivoryTower
Added null check in private constructor to prevent instantiating by Reflection call
2017-05-25 11:04:30 -05:00
f2e35ec03d #567 fix version and javadoc 2017-05-23 01:38:02 +02:00
ae1d9cf7a8 Add missing license headers 2017-05-21 09:19:29 +03:00
1bbc597671 Merge pull request #575 from prafful1/master
Few additions in README
2017-05-21 09:11:00 +03:00
4d6467e435 Merge pull request #569 from kapinuss/master
Adding Setter Dependency Injection as a second subtype of DI
2017-05-21 09:02:18 +03:00
17039dc5e9 Update AdvancedSorceressTest.java 2017-05-18 20:27:16 +03:00
30dcbee2cc Update AdvancedSorceress.java 2017-05-18 20:26:47 +03:00
08901f3c26 Update AdvancedSorceress.java 2017-05-18 20:23:05 +03:00
c746004f73 Update AdvancedSorceress.java 2017-05-18 19:13:45 +03:00
09aa44ddcb Update App.java 2017-05-18 19:13:09 +03:00
992e76ac61 Merge pull request #566 from qpi/master
Event Queue pattern
2017-05-16 21:59:50 +03:00
167a43f72e updated model.png 2017-05-15 11:04:41 +02:00
fe1e45bd69 some fixes 2017-05-15 10:40:12 +02:00
4b32fb65da Merge pull request #571 from ytian90/master
Fix Block 3 Case in Feature Toggle Design Pattern
2017-05-15 08:13:28 +03:00
0546223bba quick fix 2017-05-11 21:44:07 +02:00
857902ab95 compatibility fix
When the system is not capable to play the sound, do not throw
exception, just log it. For example on Linux there are several issues to
play sound and there are no workarounds for that :(
2017-05-11 21:41:25 +02:00
0b57edd211 Merge pull request #568 from brandon-d-mckay/patch-1
Fix incorrect URL
2017-05-09 23:10:31 +03:00
fb26d42b51 Few additions in README
Added few more points in applicability and also some use cases and consequences.
2017-05-07 13:28:54 +05:30
6857486f27 #541 Create README.md file 2017-05-04 12:33:25 +02:00
1abd96a9c8 #567 checkstyle fix 2017-05-03 22:09:47 +02:00
08c4202852 #541 fix checkstyle errors 2017-05-03 22:08:04 +02:00
6ecf994258 #567 pom.xml align fix 2017-05-03 21:42:15 +02:00
0687a3f9f8 #541 pom.xml fix align 2017-05-03 21:40:54 +02:00
64337dff06 merge fix 2017-05-03 21:07:49 +02:00
34b09c75ec #567 added .gitignore 2017-05-03 20:51:51 +02:00
66c6f30c1c #567 Updated pom.xml 2017-05-03 20:34:27 +02:00
e413b116ac Merge branch 'master' of https://github.com/4lexis/java-design-patterns 2017-05-03 19:57:57 +02:00
6e0b3e37ea updated pom.xml 2017-05-03 19:57:14 +02:00
be3f4dce50 Update Picture 2017-05-03 19:49:25 +02:00
6d87f63ed5 Added README.md 2017-05-03 19:48:29 +02:00
c92a8daeda Class diagram & fix relation between units 2017-05-03 17:59:54 +02:00
20062faae6 All without Readme and pumlid 2017-05-03 17:50:35 +02:00
678524704c Test done 2017-05-03 13:21:13 +02:00
2b229d8ea1 Update AdvancedSorceressTest.java 2017-05-02 20:38:08 +03:00
03aa99c55f Update AdvancedSorceressTest.java 2017-05-02 20:18:05 +03:00
20a4c054a7 Merge branch 'master' of github.com:ytian90/java-design-patterns 2017-04-30 00:20:48 -07:00
3ed6cc19d2 fix Block 3 case 2017-04-30 00:19:50 -07:00
87a9387e62 Merge pull request #1 from iluwatar/master
Rebase
2017-04-29 16:03:26 -07:00
8530d01e10 code implemented 2017-04-29 16:35:57 +02:00
a34e7be9c2 check commit 2017-04-28 19:35:19 +02:00
ee3744cb0a added travis supported sound files 2017-04-28 13:47:56 +02:00
2830a407ba some fixes for testing in event queue 2017-04-28 12:19:57 +02:00
ccfb6709c7 Add files via upload 2017-04-28 13:00:01 +03:00
a1c5131304 Add files via upload 2017-04-28 12:59:09 +03:00
44401988d1 pom.xml fixes 2017-04-28 11:32:35 +02:00
6e8eaf7593 adding some test cases for the event queue 2017-04-28 10:38:40 +02:00
645e91ed23 first version of pattern without Tests 2017-04-27 13:58:58 +02:00
9e7e8a64f6 Fix incorrect URL 2017-04-26 04:22:44 -04:00
152b2762c3 read.me and the diagram is added 2017-04-22 17:16:38 +02:00
82b9f4fea7 Merge pull request #544 from kemitix/data-bus
[WIP] Data Bus
2017-04-22 15:17:31 +03:00
ff8d854a8d #467 data-bus: README.md: clean up 2017-04-16 06:51:10 +01:00
31f4b15e86 Merge pull request #565 from kapinuss/patch-1
Update ObjectPool.java
2017-04-16 08:17:56 +03:00
cd54cf5512 Merge pull request #563 from sunilmogadati/SonarQubeBlockerBugs
#507 SonarQube blocker severity bugs
2017-04-16 08:13:26 +03:00
798aee47b3 Update ObjectPool.java 2017-04-12 18:59:43 +03:00
dce767c1c5 first commit 2017-04-06 23:48:15 +02:00
60ebcc56f8 #507 SonarQube blocker severity bugs 2017-04-01 20:55:47 -06:00
2643dfa0b8 #467 data-bus: App: add notes about this implementation of the patter 2017-04-01 19:33:54 +01:00
c96ebcb197 #467 data-bus: App: add description of the pattern 2017-04-01 19:26:41 +01:00
b72d545349 #467 data-bus: members: StatusMemberTest: added 2017-04-01 19:17:09 +01:00
311bb79870 #467 data-bus: members: StatusMember: records start and stop times 2017-04-01 19:16:55 +01:00
f495a88e91 #467 data-bus: members: MessageCollectorMemberTest: added 2017-04-01 19:05:19 +01:00
8b0c14cae0 Counter doesn't count anything. Added ability to collect the messages
from the MessageData that it receives.
2017-04-01 19:05:09 +01:00
b7a6a018e0 #467 data-bus: DataBusTest: added 2017-04-01 18:36:04 +01:00
46e0fa4825 #467 data-bus: pom.xml: add mockito dependency 2017-04-01 18:35:40 +01:00
86009f2261 #467 data-bus: add missing javadoc 2017-04-01 18:12:56 +01:00
146f367188 #467 data-bus: remove lombok 2017-04-01 18:12:32 +01:00
bc4d029a87 #467 data-bus: pom.xml: remove surefire plugin 2017-04-01 18:04:44 +01:00
960eee3d43 #467 update version 2017-04-01 18:04:16 +01:00
30315e788f Merge remote-tracking branch 'upstream/master' into data-bus
* upstream/master: (67 commits)
  Set version for next development iteration
  Reached milestone 1.15.0
  #539 Checkstyle fix
  #539 More Checkstyle fixes
  #539 Checkstyle fixes
  #497 Add missing puml and license headers
  #77 Add missing license header
  Work on #190: urm/puml updates * added pumlid where it was missing and possible * removed pumlid where it generated a bad image * regenerated some incorrect puml's * added 'left to right direction' puml prefix to some diagrams to improve the automatic layouting
  Removed AvoidStarImport Rule Added JavaDocType Rule
  Update App.java
  Update App.java
  Update after changes from review. Additional improvements.
  Pom.xml files fixed.
  #66 Balking Pattern
  fixed pmd violation
  fixed checkstyle violations
  diagrams added
  comments, tests and description
  changed parent POM version #69
  apply changes from review #69
  ...

# Conflicts:
#	pom.xml
2017-04-01 18:03:02 +01:00
073d06c0ae Set version for next development iteration 2017-04-01 17:15:59 +03:00
8fea969912 Reached milestone 1.15.0 2017-04-01 17:14:02 +03:00
139876f96a #539 Checkstyle fix 2017-04-01 15:51:01 +03:00
f3c4640d12 #539 More Checkstyle fixes 2017-04-01 15:43:36 +03:00
c1c4411957 #539 Checkstyle fixes 2017-04-01 15:34:13 +03:00
3f272bf291 Merge pull request #548 from muditporwal/master
Checkstyle improvements #539 : Added JavaDocType Rule
2017-04-01 14:45:52 +03:00
2921448f8b #497 Add missing puml and license headers 2017-04-01 14:25:13 +03:00
952c207a62 Merge pull request #546 from Crossy147/converter
Converter
2017-04-01 14:17:37 +03:00
6ba4d7be98 #77 Add missing license header 2017-04-01 12:39:06 +03:00
854101bb49 Merge pull request #529 from thomasoss/master
Thread Local Storage issue #77
2017-04-01 12:29:03 +03:00
a5ab5c7d8e Merge branch 'master' into converter 2017-03-26 23:50:08 +02:00
286d6c3a4c Merge pull request #536 from Rzeposlaw/master
#66 Balking Pattern
2017-03-26 15:00:21 +03:00
c2a7b902a9 Work on #190: urm/puml updates
* added pumlid where it was missing and possible
* removed pumlid where it generated a bad image
* regenerated some incorrect puml's
* added 'left to right direction' puml prefix to some diagrams to improve the automatic layouting
2017-03-25 22:07:10 +01:00
09585c3874 Removed AvoidStarImport Rule
Added JavaDocType Rule
2017-03-22 01:16:02 +08:00
f84c4c1611 Update App.java
Correction of correction ;-)
2017-03-18 10:02:37 +01:00
2c2d874ac8 Update App.java
Correction of error detected by maven-pmd-plugin.
2017-03-18 10:00:13 +01:00
72a0765ec6 Merge branch 'master' into converter 2017-03-16 12:27:05 +01:00
cca4d5a670 Update after changes from review. Additional improvements. 2017-03-13 01:33:14 +01:00
bb4a1bdc05 Pom.xml files fixed. 2017-03-13 01:16:26 +01:00
1aed5905d7 #66 Balking Pattern 2017-03-13 01:15:39 +01:00
175e9f58c1 Merge pull request #537 from robertt240/master
guarded suspension pattern #69
2017-03-12 10:36:27 +02:00
77a534385c fixed pmd violation 2017-03-11 13:35:55 +01:00
2ed7acbc31 fixed checkstyle violations 2017-03-11 13:02:29 +01:00
3a243eee6e diagrams added 2017-03-11 12:47:58 +01:00
8632bafcd7 comments, tests and description 2017-03-11 12:24:48 +01:00
449aed1a53 changed parent POM version #69 2017-03-11 12:02:04 +01:00
a20abae21c apply changes from review #69 2017-03-11 11:50:19 +01:00
7423f47daa further POM rearragments #69 2017-03-11 11:50:19 +01:00
f09578c091 further POM rearragments #69 2017-03-11 11:50:19 +01:00
29715028d1 fix in POM formatting #69 2017-03-11 11:50:19 +01:00
e5034c6ae9 guarded suspension pattern #69 2017-03-11 11:50:19 +01:00
a09866d35b another readme fix 2017-03-11 11:50:19 +01:00
1824b4138b readme fix 2017-03-11 11:50:19 +01:00
764ff4bf53 Initial commit of guarded suspension design pattern 2017-03-11 11:50:19 +01:00
e8b634c33e java docs added 2017-03-10 20:59:24 +01:00
8871f788d2 #497 Converter pattern implementation 2017-03-10 20:08:58 +01:00
e9c54011e9 Merge remote-tracking branch 'refs/remotes/iluwatar/master' 2017-03-08 16:50:04 +01:00
6b795e52c3 #467 data-bus: README.md: updated for data-bus 2017-03-05 19:43:57 +00:00
b5bdf2d7d7 #467 data-bus: etc: add urm diagrams 2017-03-05 19:43:26 +00:00
3fd6887975 #467 data-bus: implement pattern 2017-03-05 18:55:34 +00:00
eecffb0ea5 #467 data-bus: add stub 2017-03-03 19:58:03 +00:00
fd7107694a Update pom.xml
Changed
    <version>1.14.0-SNAPSHOT</version>
to
    <version>1.15.0-SNAPSHOT</version>
2017-02-18 15:16:15 +01:00
cca4760f69 #190 Rename package for Queue-Based Load Leveling pattern 2017-02-12 00:33:30 +02:00
a1ff55b462 #190 Regenerate puml files 2017-02-11 21:46:56 +02:00
ddac9dc6cb Add files via upload
Changed the classname part "runnable" to "callable"
2017-01-29 12:34:13 +01:00
2bbf84233e Delete DateFormatRunnableTestMultiThread.java 2017-01-29 12:32:44 +01:00
82f8460243 Delete DateFormatRunnableTestIncorrectDateFormat.java 2017-01-29 12:32:32 +01:00
59ea20745f Delete DateFormatRunnableTest.java 2017-01-29 12:32:21 +01:00
3d3dd58501 Update pom.xml
removed errors caused by copy code from master
2017-01-29 12:08:11 +01:00
3324e1bc43 Update pom.xml
added  <module>tls</module>
2017-01-29 12:01:32 +01:00
6202f3ab44 Add files via upload 2017-01-29 11:42:16 +01:00
453862cfc2 Delete AppTest.java 2017-01-29 11:41:46 +01:00
a8e2c157de Add files via upload
Test reworked completely. AppTest seperated.
2017-01-29 11:41:13 +01:00
080965fb17 Delete DateFormatUglyRunnable.java 2017-01-29 11:38:49 +01:00
7200329a6b Add files via upload
Rework replaces previous version completely. Using ExecutorService. Use of result object instead of static variables. Ugly example is left out.
2017-01-29 11:38:20 +01:00
f170aaa42b Delete DateFormatRunnable.java 2017-01-29 11:34:12 +01:00
c598748549 Delete AppUgly.java 2017-01-29 11:33:59 +01:00
ed11c4c4f9 Delete App.java 2017-01-29 11:33:40 +01:00
283f198ba8 Delete empty 2017-01-29 11:32:26 +01:00
15913d6382 Add files via upload
new uml diagramm after changes to the java classes
2017-01-29 11:31:06 +01:00
65e047974c Create empty 2017-01-29 11:29:19 +01:00
c529e35791 Delete tls.urm.puml 2017-01-29 11:28:27 +01:00
3342851005 Delete tls.ucls 2017-01-29 11:28:17 +01:00
c167f87ce5 Delete tls.png 2017-01-29 11:27:46 +01:00
e8fc3427c6 Update README.md
no change of content. Improved text
2017-01-29 11:23:33 +01:00
26b79a5382 Update README.md
Some additonal description, deleted wrong pumlid
2017-01-29 11:16:45 +01:00
9ec0935a1c Merge pull request #532 from leogtzr/master
Adding initialization-on-demand idiom and noninstantiable class instead of interface constant idiom
2017-01-23 08:21:07 +02:00
c6d0d28557 Reverting initialization on demand holder idiom. 2017-01-22 11:06:57 -07:00
e26215578c Changing code to use interfaces instead of implementations. 2017-01-21 15:49:29 -07:00
d6fc28e120 Changing code to use interfaces instead of implementations. 2017-01-21 15:47:54 -07:00
115a85301c #525 Add link to proxy blog 2017-01-21 13:37:16 +02:00
29c5b80f19 #525 Add link to Queue-Based Load Leveling blog 2017-01-21 12:56:42 +02:00
0c8bb1c22e Set version for next development iteration 2016-12-31 10:24:26 +02:00
0c48695fa5 Achieved milestone 1.14.0 2016-12-31 10:23:32 +02:00
8d34ccf827 Add link to Proxy presentation. 2016-12-26 20:16:30 +02:00
512a5c0560 Merge branch 'proxy-presentation' 2016-12-26 20:08:41 +02:00
9cf1918425 Add presentation for Proxy pattern. 2016-12-26 20:05:38 +02:00
5e57cd03d1 Add some material for proxy presentation. 2016-12-26 19:43:46 +02:00
6292690250 Changing constant interface pattern with a Noninstantiable class 2016-12-24 14:49:41 -07:00
ad93184a79 Merge pull request #530 from Valdar-Soft/master
Sonar quality bugfix and minor refactor
2016-12-24 12:36:11 +02:00
20b1c2bd49 Adding initialization on demand holder idiom. 2016-12-24 00:49:46 -07:00
95f2c19780 Sonar bug fixes using Yoda condition in equals expression when comparing String literal with String object.
Using try-with-resources if we use Scanner to close the underlying stream is a good practice to handle resources.
Minimal refactor.
2016-12-18 16:08:59 +01:00
120033b58b Sonar bug fixes using Yoda condition in equals expression when comparing String literal with String object.
Using try-with-resources if we use Scanner to close the underlying stream is a good practice to handle resources.
Minimal refactor.
2016-12-18 16:04:13 +01:00
e210e4ed62 Add files via upload 2016-12-16 11:17:27 +01:00
fb98da86c4 Add files via upload 2016-12-16 11:12:43 +01:00
c8b3c773c7 Add files via upload 2016-12-16 09:43:16 +01:00
61b1356976 Delete emptyfile 2016-12-16 09:42:46 +01:00
487f9ddc80 Add files via upload 2016-12-16 09:42:08 +01:00
9b7ce556e3 Create emptyfile 2016-12-16 09:35:19 +01:00
e17cf27e5a upload pom.xml 2016-12-15 18:33:52 +01:00
937a1e269d delete empty file 2016-12-15 18:32:13 +01:00
803a97237c delete empty file 2016-12-15 18:31:53 +01:00
e64f7faa3f upload junit test 2016-12-15 18:31:20 +01:00
15d660b117 empty file to create folder 2016-12-15 18:30:22 +01:00
544f7fb6d1 delete empty file 2016-12-15 18:28:02 +01:00
c4eb198a8d Upload code files 2016-12-15 18:27:28 +01:00
7067d1ae56 Create test 2016-12-15 18:24:03 +01:00
d80edd1ed3 Create test 2016-12-15 18:08:12 +01:00
aeefc11f25 Merge pull request #1 from iluwatar/master
Update my local repository
2016-12-14 08:52:22 +01:00
c94c8a3e74 Merge pull request #512 from inbravo/master
Module pattern #62
2016-12-01 20:53:12 +02:00
5d8806858b Review comments++ 2016-12-01 16:29:35 +05:30
efc2c887e9 Merge pull request #521 from Amarnath510/master
Issue #450. First commit. Queue Based Load Leveling
2016-11-28 19:04:31 +02:00
1d6d0c54a7 pom.xml Fixed Conflict 2016-11-28 20:33:45 +05:30
1387e2bc96 Fixed all the code changes after review 2016-11-28 20:13:18 +05:30
faa29f8025 Update license headers 2016-11-27 14:34:20 +02:00
89e7f51e99 Merge pull request #519 from iluwatar/presentation
Add hexagonal architecture presentation
2016-11-27 13:50:04 +02:00
cc02ff472b Merge pull request #503 from igeligel/master
Object Mother pattern #498
2016-11-26 20:22:48 +02:00
7d995056ff Update URM Version to 1.4.4 and regenerated all puml files 2016-11-26 12:51:06 +01:00
8574e06966 Proxy pattern: Add missing license header 2016-11-23 22:08:50 +02:00
82d3d7bf1f Proxy pattern: Improve the example 2016-11-23 22:03:26 +02:00
1a75ab8df1 Removed unused imports in tests 2016-11-23 09:00:04 +05:30
92f8501f7d Decorator pattern: Improve the example 2016-11-22 23:08:39 +02:00
b9ac0dc6a3 Fixed PMD issue. 2016-11-23 00:10:30 +05:30
5e7887d9be Reverted pom.xml changes that are done previously. 2016-11-22 12:21:24 +05:30
e8f7187e4b Updated pom.xml with maven-pmd-plugin
Added dependency "maven-pmd-plugin" to the pom file.
2016-11-22 12:06:54 +05:30
d6b5456f98 Updated checkstyle errors. 2016-11-20 23:36:23 +05:30
52a81eb368 Issue #450. Updated pom.xml 2016-11-20 21:55:56 +05:30
12b70cb39c Issue #450. First commit. Queue Based Load Leveling 2016-11-20 16:25:10 +05:30
68ec24c62e Merge pull request #515 from dbryla/master
#502 Added logging framework to repository
2016-11-18 20:47:17 +02:00
3091ff21b0 #502 Reduced amount of information logged 2016-11-17 09:54:10 +01:00
95b651f177 Merge pull request #520 from thomasoss/patch-1
Update App.java
2016-11-15 21:31:34 +02:00
f67d2fd9a9 Review comments++ 2016-11-15 13:01:37 +05:30
4ff8fa3721 Review comments++ 2016-11-15 12:59:05 +05:30
9180bb0fef Update App.java
The relationship between decorator and target (in the code example between Troll und SmartTroll) ist not a composition as described in the code comment lines of class App. It's a aggregation. In a composition both instances canncot live without the other one. But the target (Troll) could live without the decorator (Smart Troll). Changed "composition" to "aggregation" in the comment lines. Code lines are unchanged.
Greetings Thomas
2016-11-14 16:43:58 +01:00
1abf5b11c3 Add presentation link to README.md 2016-11-13 11:37:49 +02:00
22d973c460 Merge branch 'master' into presentation 2016-11-13 11:34:14 +02:00
c850295aab Add new diagram 2016-11-13 11:23:22 +02:00
4c24d99414 Work on Hexagonal Architecture presentation 2016-11-12 22:44:08 +02:00
e1ae1067db Link Hexagonal Architecture pattern to corresponding blog entry 2016-11-06 12:26:03 +02:00
6f3e2985a4 Create presentation template 2016-11-06 12:14:39 +02:00
b37190a214 #502 Introduced logging in new example 2016-11-04 12:19:32 +01:00
0a427710bb Merge branch 'master' of https://github.com/iluwatar/java-design-patterns
* 'master' of https://github.com/iluwatar/java-design-patterns: (27 commits)
  Remove use of coveralls-maven-plugin (sonarqube.com covers this)
  Add SonarQube.com badge
  Fix environment variable
  Add Travis instructions for SonarQube.com analysis
  Adds more criticism to Singleton pattern.
  Event Based Asynchronous pattern: Add missing license header and puml diagram
  Changed config to non-interactive
  Moved config into a separate dir
  Unused import removed.
  End process logic clause has been corrected.
  Caching pattern: Documentation and diagram
  Fixes #437. Adds criticism to Singleton pattern.
  Alter JUnit tests to run in lesser time.
  Updated version snapshot to 1.14.0
  Changes based on review feedback.
  Closes #436. Adds criticism to service locator pattern.
  Caching pattern: Implementation of Cache-Aside pattern
  Caching pattern: Style fix for null check
  Caching pattern: Refactor LRU cache to avoid NPE and unnecessary cache lookup
  Caching pattern: Refactor shutdown hook to use method reference
  ...
2016-11-04 11:51:45 +01:00
e138163c4f #502 Adjusted tests for logger introduction 2016-11-04 11:47:06 +01:00
124fd33da0 Remove use of coveralls-maven-plugin (sonarqube.com covers this) 2016-11-01 21:31:54 +02:00
9433c78d29 Merge pull request #510 from bellingard/patch-1
Add SonarQube.com badge
2016-10-28 20:39:55 +03:00
932700d9b1 Merge pull request #506 from dzmitryh/master
Cosmetic fixes in async-method-invocation
2016-10-28 19:13:17 +03:00
27d6d500bc #502 Reverted changes in composite example, due to nature of this example using logger isn't good idea 2016-10-28 09:35:59 +02:00
ea7752c5e1 checkstyle errors removed
checkstyle errors removed
2016-10-27 18:30:07 +05:30
7ba6cb43fd App
App
2016-10-27 16:00:01 +05:30
1ace4c05d6 App++
App++
2016-10-27 15:59:51 +05:30
7015e95ac3 SecondCut++
SecondCut++
2016-10-27 15:55:08 +05:30
2a77ac29e9 FirstCut++
FirstCut++
2016-10-26 16:59:36 +05:30
6aed26e61e Fix pom.xml
Deleted </modules> tag because i added it one time more than neccessary
2016-10-24 15:43:52 +02:00
74ac79b01e Fix pom.xml 2016-10-24 15:33:25 +02:00
750fa4f954 Merge Changes of the master repository 2016-10-24 15:32:32 +02:00
20295316c2 add entry to parent pom.xml #498 2016-10-24 15:30:17 +02:00
56b0884258 Change name of variables in test #498 2016-10-24 15:28:27 +02:00
0438811489 #502 Replaced usages of System.out with logger. 2016-10-23 19:59:03 +02:00
1c02785927 Add SonarQube.com badge 2016-10-23 14:35:45 +02:00
19cb715d20 Fix environment variable 2016-10-19 23:08:51 +03:00
ffdaf2ec47 Add Travis instructions for SonarQube.com analysis 2016-10-19 22:25:37 +03:00
a37a29e12b Merge pull request #500 from dmitraver/master
Adds criticism to a Service Locator and Singleton patterns.
2016-10-18 21:01:58 +03:00
b66e8ecef9 Adds more criticism to Singleton pattern. 2016-10-18 14:18:47 +02:00
99677867c6 Event Based Asynchronous pattern: Add missing license header and puml diagram 2016-10-18 07:51:37 +03:00
0f7b44c3b1 Merge pull request #483 from waisuan/master
Issue #469: Event-based Asynchronous pattern
2016-10-18 07:43:01 +03:00
70318123fe Changed config to non-interactive 2016-10-17 22:22:06 +01:00
986c529eb6 Moved config into a separate dir 2016-10-17 21:29:03 +01:00
64bdab46b9 Merge pull request #495 from christofferh/feat/cache-aside
Caching pattern: Cache-Aside
2016-10-17 22:49:16 +03:00
37b930c3b7 Unused import removed. 2016-10-15 14:29:32 +03:00
85060784a7 End process logic clause has been corrected. 2016-10-15 14:27:15 +03:00
f114b5b957 Caching pattern: Documentation and diagram 2016-10-09 12:43:43 +02:00
863ea75381 Add PlantUML file for the UML diagram #498 2016-10-06 20:12:43 +02:00
3a9d1684fd Initial commit of the object mother #498
Add a simple king and queen classes which implement the behaviour of the
royalty interface. Also wrote the object mother of royalty objects which
is final so you can just call the static methods in it to create objects
with a specific state to use them fast in tests. The tests are already
created for testing the behaviour and the type of the objects which are
created by the object mother.
I also created the UML diagrams via object aid and updated the readme.
2016-10-04 22:33:06 +02:00
eea8785a22 Fixes #437. Adds criticism to Singleton pattern. 2016-10-04 14:34:01 +02:00
8f1758c28f Alter JUnit tests to run in lesser time. 2016-10-03 21:46:16 +01:00
622376e0fa Updated version snapshot to 1.14.0 2016-10-03 21:16:23 +01:00
5eacf522a2 Merge remote-tracking branch 'upstream/master' 2016-10-03 21:05:31 +01:00
12544caa75 Changes based on review feedback. 2016-10-03 21:05:11 +01:00
9512f3ec70 Closes #436. Adds criticism to service locator pattern. 2016-10-03 21:59:36 +02:00
4ca205c03c Set version number for next development iteration 2016-09-30 19:40:28 +03:00
c5e6dcc11b Reached milestone 1.13.0 2016-09-30 19:38:28 +03:00
b31edda3cf Caching pattern: Implementation of Cache-Aside pattern 2016-09-22 20:41:26 +02:00
e3355d76d1 Caching pattern: Style fix for null check 2016-09-22 20:36:02 +02:00
865f788612 Caching pattern: Refactor LRU cache to avoid NPE and unnecessary cache lookup 2016-09-22 20:35:44 +02:00
6ed842e58b Caching pattern: Refactor shutdown hook to use method reference 2016-09-22 20:34:46 +02:00
69cab15d75 Merge remote-tracking branch 'upstream/master' 2016-09-19 21:50:54 +01:00
371b262a51 Changes based on latest code review 2016-09-19 21:50:23 +01:00
dbd605e378 Changes based on latest code review 2016-09-19 21:50:04 +01:00
6026eedd51 UML generation: Mark the urm-maven-plugin execution to be ignored in Eclipse and recreate all .puml files 2016-09-18 17:51:09 +03:00
b030cd4eba Hexagonal pattern: Introduce lottery utils class 2016-09-17 09:20:33 +03:00
6aa58e8ae6 Hexagonal pattern: Remove unnecessary factories 2016-09-17 09:07:06 +03:00
914d1353a1 Hexagonal pattern: Update test application description 2016-09-15 21:56:15 +03:00
df32a7b893 Hexagonal pattern: Introduced lottery events port with two adapters 2016-09-15 21:45:09 +03:00
c4c5e78e50 Hexagonal pattern: Improve error handling in console lottery 2016-09-14 22:18:42 +03:00
3cf2b34d2a Hexagonal pattern: Improve connection properties handling 2016-09-14 22:01:41 +03:00
27e8cb7f2d Hexagonal pattern: Add separate class for Mongo connection properties 2016-09-14 19:25:26 +03:00
e685512ed5 Hexagonal pattern: Added Mongo based banking adapter and bound it in Guice production module 2016-09-11 23:19:02 +03:00
f2159515bc Merge remote-tracking branch 'upstream/master' 2016-09-11 20:33:51 +01:00
59e6a0af85 Hexagonal pattern: Ignore Mongo repository test 2016-09-11 22:16:50 +03:00
9a90f2de1f Changes based on code review 2016-09-11 18:45:51 +01:00
626c56730c Hexagonal pattern: Added Mongo based ticket repository and set production configuration to use that 2016-09-11 20:02:34 +03:00
fce30db803 Updating fork branch 2016-09-11 16:24:16 +01:00
a85463470e Hexagonal pattern: Add mongo driver dependency 2016-09-11 13:53:00 +03:00
4410419914 Hexagonal pattern: Simplified lottery ticket ids 2016-09-11 10:34:12 +03:00
e17d72bca8 Hexagonal pattern: Added console interfaces for players and administration. 2016-09-10 14:28:05 +03:00
121ed3cca8 Hexagonal pattern: Move lottery administration and service to the core. Introduce console interfaces for players and administartors. 2016-09-10 07:56:37 +03:00
adc6019c7e Hexagonal pattern: Remove interfaces with only one implementation 2016-09-10 07:14:24 +03:00
0f2807b9cf Hexagonal pattern: More descriptive class names 2016-09-09 21:36:17 +03:00
1b10ddbb73 Hexagonal pattern: Use Guice dependency injection 2016-09-06 22:39:39 +03:00
348e577e8e Hexagonal pattern: Add Guice dependency 2016-09-06 21:39:08 +03:00
22821ba8cc Move Guice to parent pom dependency management section 2016-09-06 21:35:36 +03:00
4493341ba6 add documentation to 'use latest java 8' change 2016-09-04 11:00:24 +02:00
3cb872807e Hexagonal pattern: remove unnecessary repository usage from a unit test 2016-09-04 10:33:26 +03:00
ab68129829 Hexagonal pattern: move business logic to core 2016-09-03 22:02:08 +03:00
e57a0948ef Merge pull request #490 from iluwatar/DocumentUsages
#211 Document GoF usages from Java API
2016-09-03 14:14:13 +03:00
233f1e69f9 Removed PUBLIC modifiers from IEvent 2016-09-03 11:32:31 +01:00
f11597136f Fixed Checkstyle errors. 2016-09-03 11:32:29 +01:00
e1836fee2f Updated parent POM to include new pattern (Event-asynchronous) 2016-09-03 11:32:28 +01:00
2d99061902 Issue #469: Implementation of Event-based Asynchronous pattern 2016-09-03 11:32:25 +01:00
ff23e90c4f Add puml for Promise pattern 2016-09-03 08:43:35 +03:00
fa52a7f77e Run build with latest java 8 release 2016-09-03 00:19:50 +02:00
165d1f1298 Turn Error Tracing on when installing
Travis currently errors and i cant reproduce locally, so this might help finding the culprit
2016-09-02 23:54:52 +02:00
be2c7fdb2b Update URM version: 1.4.0 -> 1.4.1, fixes #492 2016-09-02 23:15:38 +02:00
90c636abd3 Add missing license headers 2016-09-02 21:28:45 +03:00
678a06e7f8 Merge pull request #470 from iluwatar/Promise
Implements #403 Promise pattern
2016-09-02 20:47:21 +03:00
e425c2ef2f Add webhook for travis build failures to gitter
Only the core group (private) gitter room
2016-08-31 13:15:44 +02:00
5c1a4f1caf Added example that mocking frameworks use proxy pattern 2016-08-31 16:12:13 +05:30
58dce1bd89 Work on #190: Commit initial pumlId's added by the script 2016-08-30 15:10:34 +02:00
9dd1503e6f Work on #190: add postPumlsToServer.py python script
Used to initially post all pumls to the plantuml hosting while preserving the pumlId's
2016-08-30 15:07:49 +02:00
09037b0251 Rename index.md to README.md
to conform to our standards, every other file is named README.md
2016-08-30 14:06:14 +02:00
36fe249960 Work on #190: Add first batch of automagically generated puml files 2016-08-30 13:29:12 +02:00
e73867f9a1 Work on #190: Add automagic puml generation in pom.xml's 2016-08-30 13:24:53 +02:00
59cf100302 #403, updated javadocs 2016-08-29 12:04:24 +05:30
ad11ea46b1 Work on #403, javadocs updated 2016-08-29 11:55:30 +05:30
5796e1967f Work on #403, updated diagram and finishing touches 2016-08-29 11:50:33 +05:30
483c61a82a Some refactoring, added javadocs 2016-08-29 00:16:36 +05:30
6575b3ae99 Merge pull request #491 from alexsomai/patch-1
Minor code changes
2016-08-29 00:00:44 +05:30
095adda7e9 Change access level to private 2016-08-26 12:54:20 +03:00
f16ae08bdf Remove extra space 2016-08-26 12:46:30 +03:00
95cf9fe367 Work on #403, made example readable and moved methods into utility 2016-08-22 18:43:29 +05:30
28647cdf48 #211, consistent use of real world examples section in all readme files. 2016-08-20 20:57:48 +05:30
fdcf546112 Merge branch 'master' of https://github.com/iluwatar/java-design-patterns into DocumentUsages 2016-08-20 20:50:30 +05:30
a0c77c32b5 #211 added further examples for structural and behavioral patterns 2016-08-20 20:49:28 +05:30
eb75773891 Added FAQ on Memento pattern
Difference between java Serialization and Memento pattern added
2016-08-20 19:44:48 +05:30
c79df708b1 #211 added real world examples from Java api for creational patterns 2016-08-20 13:17:53 +05:30
56100927a9 Addendum #481
Change page-index for faq.md
2016-08-15 12:33:24 +02:00
7e77216919 remove link, resolves #479
to avoid confusion, the link is removed.
For more information on why this is done please look at the referenced issue
2016-08-15 11:53:39 +02:00
b16d7fc970 Configure Travis notification email 2016-08-14 23:00:27 +03:00
0b36a3153d Fix checkstyle error 2016-08-14 22:42:59 +03:00
7c2f5da926 Add final keyword 2016-08-13 18:28:53 +03:00
ffbc5f2f29 Reorganize LotteryNumbers for easier inclusion in the blog 2016-08-13 17:08:57 +03:00
d50139e13e Merge pull request #478 from iluwatar/DocumentDoubleCheckIdiom
Documented singleton double check idiom
2016-08-05 18:45:00 +03:00
d484e7f731 Documented singleton double check idiom, explaining the dynamics that happen on each step for better understanding. Did this due to a PR #475 2016-08-05 14:38:25 +05:30
76970633b8 Work on #403, incorporate review changes 2016-08-04 18:10:50 +05:30
55028a49dc Merge pull request #476 from sumityadav6541/master
removed extra "is" from javadoc comments
2016-08-04 17:47:37 +05:30
94c3a2caf3 removed extra "is" from the javadoc of InitializingOnDemandHolderIdiom class 2016-08-03 15:02:46 +05:30
547d798528 Merge pull request #1 from iluwatar/master
merging changes into fork from origin
2016-08-03 14:57:07 +05:30
8953bfc81b Merge pull request #1 from iluwatar/master
Bringing fork up-to-date
2016-08-01 16:55:27 +01:00
e7be94d2e4 Merge branch 'Promise' of https://github.com/iluwatar/java-design-patterns into Promise 2016-07-29 13:12:33 +05:30
383e4a3a0b Merge branch 'master' of https://github.com/iluwatar/java-design-patterns into Promise 2016-07-29 13:01:51 +05:30
3001fa4a30 Merge pull request #471 from Crossy147/issue-#459
#459 added known alias for monostate pattern
2016-07-27 15:46:17 +03:00
5fcef89384 #459 added known aliast for monostate pattern 2016-07-26 20:33:43 +02:00
40ac552542 Work on #403, added README 2016-07-24 01:45:49 +05:30
09ba5ca656 Work on #403, added class diagrams and javadocs 2016-07-22 18:34:05 +05:30
eb560f5f54 Work on #403, removed checkstyle violations 2016-07-22 16:53:01 +05:30
2b945ca27f Work on #403, removed dependency on async method invocation module, added more tests 2016-07-22 16:47:52 +05:30
4bd1f14cfb Merge branch 'master' of https://github.com/iluwatar/java-design-patterns into Promise 2016-07-22 12:52:54 +05:30
bc94d0fc26 Fix link 2016-07-21 20:21:36 +03:00
102341443d Work on #403, added application class and test cases. 2016-07-21 19:13:42 +05:30
8124fd0771 Adjust pattern categories and tags 2016-07-21 09:27:48 +03:00
ea7503414e Work on #403, added basic implementation of promise pattern 2016-07-20 19:58:20 +05:30
d4c2f0392d Merge pull request #464 from pnowy/#463-chain-of-responsibility
#463 Added javax.servlet.Filter to real world examples intercepting filter
2016-07-18 09:22:34 +03:00
f7b7f15ec8 #463 Added javax.servlet.Filter to real world examples of intercepting filter 2016-07-17 21:24:12 +02:00
0fbbd8dc81 #463 Added javax.servlet.Filter to real world examples of chain 2016-07-17 16:05:07 +02:00
9f0320aeaf Add some tags to Page Object 2016-07-13 00:02:20 +03:00
fe1d760c7f Fix license headers 2016-07-12 19:52:56 +03:00
b46d2deeb0 Merge pull request #434 from colinbut/master
#229 Page Object Pattern
2016-07-12 19:47:48 +03:00
f182e87ee1 fixed app launch 2016-07-10 20:51:52 +01:00
85f432fb54 exclude library class from jacoco code coverage 2016-07-09 22:24:17 +01:00
7be98fa829 added missing licence headers to 2 files 2016-07-09 22:20:13 +01:00
ff8037ee0b Add aliases for Specification pattern 2016-07-07 08:46:56 +03:00
849df50394 Fix formatting 2016-07-04 22:22:37 +03:00
f806c5b712 Add known uses to Factory Method 2016-07-04 21:52:39 +03:00
ef2ada4fdf syncing fork 2016-07-03 21:47:07 +01:00
5d58a1b333 syncing fork 2016-07-03 21:46:38 +01:00
4a069ee93a new class diagrams 2016-07-03 21:36:03 +01:00
88321890c7 remove old class diagram 2016-07-03 21:12:48 +01:00
b1e40d9c92 Feedback changes - final and refactored code 2016-07-03 21:12:09 +01:00
5c26f46174 Set version number for next development iteration 2016-06-30 18:15:26 +03:00
7a118e4209 Reached milestone 1.12.0 2016-06-30 18:14:41 +03:00
4eac37c6b5 Feedback changes - removed file 2016-06-28 22:04:39 +01:00
c212ee5cb1 Feedback changes - fix dependency in pom 2016-06-28 22:03:57 +01:00
8efaf44170 Feedback changes - sort out dependency 2016-06-28 22:02:03 +01:00
27e4e9afee Feedback changes - restructed project structure 2016-06-28 21:53:55 +01:00
35c0942803 syncing fork 2016-06-27 20:54:45 +01:00
e7bd3cade2 Update link for Naked Objects paper 2016-06-26 20:23:05 +03:00
f2e1982264 Merge pull request #435 from protopapa/aggregator-microservices
implementation of microservices architectural pattern #296
2016-06-26 17:32:42 +03:00
27bbbd8335 fix bug 2016-06-26 14:57:27 +02:00
6677d1091d implementation of microservices architectural pattern #296 2016-06-23 22:54:44 +02:00
0282d6663f README 2016-06-18 21:08:15 +01:00
c8f04d2f0d added Class Diagram 2016-06-18 19:20:29 +01:00
53fc8b749a Page Object pattern implementation 2016-06-18 15:40:03 +01:00
f57b94ab47 Merge pull request #433 from qza/master
Abstract Document
2016-06-07 22:32:00 +03:00
34431d71b4 Merge pull request #431 from VarunVats9/master
Renamed HeroBuilder to Builder
2016-06-05 09:20:54 +03:00
qza
afdeba4f9a #355 finalize example 2016-06-04 20:06:32 +02:00
qza
c229ec23b3 #355 clean up 2016-06-02 07:41:32 +02:00
qza
f3110de130 #355 handle case when there are no child elements for the given key 2016-06-02 07:32:48 +02:00
qza
43f90ead48 #355 abstract document test 2016-06-02 07:29:37 +02:00
qza
a372f05e41 #355 override toString to log properties 2016-06-02 07:27:35 +02:00
qza
32b647323c #355 class diagrams 2016-06-01 22:21:31 +02:00
qza
913411773f #355 document, abstract base, traits and example domain 2016-06-01 22:20:55 +02:00
qza
c1187ae0d7 #355 init abstract-document module 2016-05-31 20:12:27 +02:00
509de9782d renamed HeroBuilder to Builder 2016-05-29 20:05:54 +05:30
f6649a4fed Markdown fix 2016-05-22 09:33:50 +03:00
9de2cbe73e Merge pull request #421 from iluwatar/hexagonal
Implements #86 Hexagonal Architecture
2016-05-21 22:19:16 +03:00
75ed1b1a96 Review fixes 2016-05-21 21:48:25 +03:00
2ed3748c9b Improve Singleton holder example 2016-05-07 11:38:55 +03:00
0ad9937881 Merge pull request #427 from surgeforward/297
#297 Create API Gateway pattern
2016-05-06 10:14:31 +03:00
f234a6875c #297 Update class diagram to reflect new location of files 2016-05-03 17:41:37 -05:00
dd2385312b #297 Add new dependencies to java-design-patterns/pom.xml and reference them from api-gateway submodule pom.xml files 2016-05-03 17:37:33 -05:00
8653eb87bc #297 Move API Gateway code into a new submodule: api-gateway-service. Change api-gateway packaging type to "pom". Update price-microservice and image-microservice to be true submodules of api-gateway 2016-05-03 17:17:36 -05:00
a6036e5787 #297 Update category and tags in README 2016-05-03 16:29:20 -05:00
5abd20f9e1 #297 Update license headers 2016-05-03 16:28:20 -05:00
b115c61873 #297 Fix error in README 2016-04-24 16:05:38 -05:00
b92318ae36 #297 Increase version number 2016-04-24 16:00:53 -05:00
28d259a55c #297 Create README.md 2016-04-24 16:00:39 -05:00
9a9df80080 Merge branch 'master' of https://github.com/iluwatar/java-design-patterns into 297
Conflicts:
	pom.xml
2016-04-24 15:30:35 -05:00
a54cea777f #297 Create class diagrams for API Gateway, Price microservice, and Image microservice 2016-04-24 15:24:33 -05:00
71e3443e0e Fix permalink to represent its current dir
Otherwise the picture cant be found, as the jekyll build process will put this file in a 'dm' directory and the other stuff like resources in a 'data-mapper' directory (because resources dont have permalink specified they are served static)
2016-04-24 12:58:38 +02:00
bf7b682549 Add License Shield 2016-04-24 12:25:05 +02:00
5b72510c1c Merge pull request #417 from inbravo/master
Data Mapper #34
2016-04-24 00:02:48 +03:00
49ca63087c Merge branch 'master' into hexagonal
# Conflicts:
#	pom.xml
2016-04-20 22:32:22 +03:00
af1db79aa7 version++ 2016-04-20 07:23:12 +05:30
59e9d027d4 version++ 2016-04-19 12:45:12 +05:30
018a4e52a2 build error fix++ 2016-04-19 12:23:52 +05:30
93b0b3730e build error fix++ 2016-04-19 11:59:27 +05:30
d5f7cb4e2c build check style error-- 2016-04-19 11:49:35 +05:30
8fa774d420 mvn build file++ 2016-04-19 11:35:13 +05:30
28c2714862 review comments++
review comments++
2016-04-19 11:25:42 +05:30
534fb67eb0 Merge pull request #397 from gwildor28/master
Lock Pattern #71: Added mutex and semaphore modules to demonstrate locks
2016-04-18 21:12:29 +03:00
32736fc90c uml diagram++ 2016-04-18 17:05:18 +05:30
8529d6e34b First review changes++
First review changes++
2016-04-18 13:14:20 +05:30
a2843297d8 JUnit tests 2016-04-17 14:46:52 +01:00
886ad7e8f0 Fix some markdown errors 2016-04-16 08:52:16 +03:00
6f89315aa9 Fix minor display error on web site 2016-04-15 08:41:15 +03:00
cf0570a5ed Fix display error 2016-04-15 08:38:08 +03:00
8e69ebce9f Fix display error 2016-04-15 08:21:29 +03:00
439e286f00 Fix minor display error 2016-04-15 08:13:51 +03:00
e821abdb1b updated version to fix pom 2016-04-14 17:44:18 +01:00
685d093cff added relative paths to pom in mutex/semaphore 2016-04-14 17:33:52 +01:00
ca8be7c43e pom update 2016-04-13 19:26:31 +01:00
3f9a756657 pom update 2016-04-13 19:25:02 +01:00
1fd15d535b Merge remote-tracking branch 'refs/remotes/iluwatar/master' 2016-04-13 18:51:55 +01:00
b72214da2f Fix H2 database path problem 2016-04-12 23:04:37 +03:00
a7dfe7681e Add alias names 2016-04-11 23:17:27 +03:00
cfda338617 Fix version number 2016-04-10 22:03:24 +03:00
e546d5dacc Add general description for the example code 2016-04-10 21:50:02 +03:00
c2f4194c07 Add alias name for the pattern 2016-04-10 21:49:40 +03:00
ccc1ec921a Add readme and class diagram 2016-04-10 21:22:40 +03:00
9b3aa785ed Add missing license headers 2016-04-09 17:21:27 +03:00
0fe8eec610 Fix merge conflict 2016-04-09 17:17:29 +03:00
68725bf3cc Merge branch 'master' into hexagonal 2016-04-09 17:16:07 +03:00
5de9c7e6b4 Lots of improvements to the example 2016-04-09 16:53:34 +03:00
48803d4c7d Add example lottery run 2016-04-09 16:01:47 +03:00
b94a705161 Add constants for win sum and prize payer's bank account 2016-04-09 15:14:12 +03:00
335737d7dd Add alias for Multiton 2016-04-06 20:37:02 +03:00
06e0a15400 Applicability++ 2016-04-06 13:18:42 +05:30
c53dcf1274 Intent++ 2016-04-06 13:14:10 +05:30
822ab8d9fd Second type mapper is updated to use java.util.vector
Second type mapper is updated to use java.util.vector
2016-04-04 16:35:22 +05:30
59b6b817f4 Test/Doc added
Test/Doc added
2016-04-04 15:31:43 +05:30
eb72493f13 JDBC removed... 2016-04-04 12:33:43 +05:30
deb15e2733 JDBC removed... 2016-04-04 12:24:15 +05:30
d631585fa8 Test commit for #255
ignore the minor documentation change.
This is to test our build chain with travis!
2016-04-03 20:04:56 +02:00
4ebb64c092 #297 Create unit test for PriceController 2016-04-02 18:33:50 -05:00
e80583fad7 #297 Create unit test for ImageController 2016-04-02 18:31:58 -05:00
665256ecc0 #297 Create Spring Boot-backed API Gateway that aggregates calls to the Image and Price microservices 2016-04-02 18:25:13 -05:00
01737bc643 #297 Create Spring Boot-backed Price microservice with an endpoint to retrieve a price 2016-04-02 18:19:42 -05:00
0c6d3f2c3a #297 Create Spring Boot-backed Image microservice with an endpoint to retrieve an image path 2016-04-02 18:19:21 -05:00
398eb11b11 Set version for the next development iteration 2016-04-02 19:55:04 +03:00
1f27dbbf5b Set version for milestone 1.11.0 2016-04-02 19:51:03 +03:00
187658cce9 Merge remote-tracking branch 'iluwatar/master' 2016-03-29 14:19:01 +01:00
e2af78f417 Update According to Review Comments #397
Resubmit of updates
2016-03-29 13:42:54 +01:00
474f2658ee Merge remote-tracking branch 'refs/remotes/iluwatar/master' 2016-03-29 13:36:56 +01:00
28a5a43a47 basic implementation ++
basic implementation ++
2016-03-29 16:36:00 +05:30
d20145c05d Merge pull request #407 from iluwatar/refactor-dao
Solves #404 Refactor dao
2016-03-28 19:44:07 +03:00
464ae1690b Updated pom 2016-03-28 11:59:29 +05:30
ddbc61b140 Incorporated review changes - 1) Created sql file for central schema 2)
Changed getById return type to Optional
2016-03-28 11:55:22 +05:30
f32a3892a3 Merge branch 'master' of https://github.com/iluwatar/java-design-patterns into refactor-dao 2016-03-28 11:06:25 +05:30
6608a8de38 Utilize notifications and banking 2016-03-27 23:35:51 +03:00
28d3cb2aa2 Add notifications implementation 2016-03-26 22:01:31 +02:00
11c0654103 Add banking implementation 2016-03-26 21:47:25 +02:00
f620123cee Organize packages 2016-03-26 21:22:49 +02:00
d406f0f9c6 Merge pull request #412 from slawiko/patch-1
Override annotation added
2016-03-26 21:03:34 +02:00
ac468bb7e7 Added high level lottery test 2016-03-26 15:54:40 +02:00
0c56d800c5 Override annotation added
I think this is a typo
2016-03-26 15:22:33 +03:00
4bb7ddaec1 Work on admin tests 2016-03-26 12:42:23 +02:00
39a1c1e956 Implement admin interface 2016-03-26 12:28:51 +02:00
656b599687 Refactor to test utils 2016-03-26 12:28:31 +02:00
9074a9ca05 Merge branch 'saifulazad-patch-1' 2016-03-26 15:54:38 +05:30
b14aff17b6 Updated failing test cases 2016-03-26 15:54:10 +05:30
20c1e2ea80 Merge branch 'patch-1' of https://github.com/saifulazad/java-design-patterns into saifulazad-patch-1 2016-03-26 15:50:25 +05:30
100a72a5e2 Merge pull request #402 from iluwatar/mute-idiom
Implements Mute idiom
2016-03-26 11:07:46 +02:00
8d6bc522cd Simplify lottery ticket submit 2016-03-26 11:03:40 +02:00
a395316a80 Added readme 2016-03-26 13:54:03 +05:30
80875a9ac8 Removed dependency on Mockito from pom 2016-03-26 12:36:50 +05:30
4d820b12ff Changes after review. Added README 2016-03-26 12:33:02 +05:30
e543ee0a9c Merge branch 'master' of https://github.com/iluwatar/java-design-patterns into mute-idiom 2016-03-26 12:11:09 +05:30
2f5a2be27a Fix missing table error 2016-03-25 22:00:08 +02:00
e549af25dd Severe is not appropriate.
"Sever" is most Appropriate
2016-03-25 22:50:17 +06:00
6e4b269939 Update according to review comments #397
- Added descriptions
- Added junit tests
- Added javadoc
- Added index.md
- Added class diagrams
2016-03-24 18:13:37 +00:00
3f7ead5ca5 Work on #404, updated class diagram and javadoc. Passed checkstyle checks 2016-03-23 13:13:19 +05:30
266b658ab5 Refactor interfaces 2016-03-22 22:45:25 +02:00
d2f620a5e6 Added tests for lottery ticket repository 2016-03-22 21:27:13 +02:00
aebd857931 Merge pull request #406 from slawiko/slawiko-patch-1
File renaming (index.md to README.md)
2016-03-22 12:22:35 +01:00
fa077c8be9 Work on #404, javadocs and test cases for DB and in memory dao. 2016-03-21 17:55:29 +05:30
8b147c4dd9 Add mock database for lottery tickets 2016-03-20 20:56:04 +02:00
fde33999b7 Added interface for lottery administrators 2016-03-20 14:38:24 +02:00
e8671e1d6e Add interface for lottery event notifications 2016-03-20 14:33:41 +02:00
15d2b9dcca Added interface to lottery service provider's bank account 2016-03-20 14:26:43 +02:00
95e6a67056 Added interface for accessing lottery tickets in database 2016-03-20 14:09:44 +02:00
2785f6915b Add lottery ticket check result 2016-03-20 11:10:06 +02:00
bd1b65276e all index.md files renamed to README.md for more compatibility with github 2016-03-20 11:50:21 +03:00
804ffc3ea7 Added lottery service interface 2016-03-20 10:49:31 +02:00
035b14fef8 Added lottery ticket and unit tests 2016-03-19 21:57:57 +02:00
81718eb8ae Added player details and unit tests 2016-03-19 21:08:55 +02:00
cd3a5d48d8 Work on lottery numbers unit tests 2016-03-19 20:37:36 +02:00
b0f96adeb1 Added class for lottery numbers and unit tests for it 2016-03-19 18:13:30 +02:00
448d855809 implemented and added test cases for DB dao. Added dependency of Hierarchical junit runner in parent pom 2016-03-18 16:39:45 +05:30
f6a20c7693 Refactoring changes to DAO pattern. Renamed default dao implementation to InMemory and refined interface 2016-03-16 18:47:07 +05:30
e5217bbde8 Work on #385, added missing license template 2016-03-16 12:48:53 +05:30
40e5c8d587 Merge branch 'master' of https://github.com/iluwatar/java-design-patterns into mute-idiom 2016-03-16 12:41:15 +05:30
c78dd2667a Work on #385, added documentation and class diagram. Made refactoring changes to pass checkstyle and PMD checks 2016-03-16 12:40:46 +05:30
7aff77ab27 Used mockito to replicate SQLException while closing connection to show use of loggedMute 2016-03-15 18:44:59 +05:30
528d179efe Add missing license headers 2016-03-13 17:29:09 +02:00
06546ae3cf Fix license headers 2016-03-13 17:23:31 +02:00
2ed089900d Initial commit for Hexagonal Architecture pattern 2016-03-13 17:23:15 +02:00
984bf552ce Merge pull request #390 from DevFactory/release/private-methods-that-don't-access-instance-data-should-be-static-fix-1
squid:S2325 - private methods that don't access instance data should …
2016-03-09 18:33:17 +02:00
414cdfa332 Merge pull request #398 from legka/master
Event driven architecture refactored.
2016-03-09 10:49:08 +05:30
afb897300b Event driven architecture refactored.
1. Renamed Message to Event and Event to AbstractEvent
2. Generified Event and Handler
3. Updated EventDispatcher to make unsafe configuration impossible
4. Updated UML diagram accordingly
2016-03-08 00:56:08 -08:00
3ed3bc1fa5 Added mutex and semaphore modules to demonstrate locks
Added two modules to demonstrate locks.

Mutex demonstrates a simple mutual exclusion lock. Semaphore
demonstrates a semaphore for controlling access to a pool of resources.

The main class of both programs is App.java.
2016-03-07 19:40:50 +00:00
adb94044ff Work on #385, created project and provided two mute methods 2016-03-01 17:28:28 +05:30
35d6a54831 Merge pull request #391 from DevFactory/release/Useless-parentheses-around-expressions-should-be-removed-to-prevent-any-misunderstanding-fix-1
squid:UselessParenthesesCheck - Useless parentheses around expression…
2016-02-29 17:53:13 +05:30
f135ef6ec8 Merge pull request #389 from DevFactory/release/Declarations-should-use-Java-collection-interfaces-such-as-List-rather-than-specific-implementation-classes-such-as-LinkedList-fix-1
squid:S1319 - Declarations should use Java collection interfaces such…
2016-02-29 07:42:04 +02:00
046e131119 squid:UselessParenthesesCheck - Useless parentheses around expressions should be removed to prevent any misunderstanding 2016-02-23 20:57:55 +02:00
e4c34b1e22 squid:S1319 - Declarations should use Java collection interfaces such as List rather than specific implementation classes such as LinkedList 2016-02-23 12:32:23 +02:00
3791a80978 squid:S2325 - private methods that don't access instance data should be static 2016-02-22 19:15:51 +02:00
ab19c47415 Merge pull request #388 from Crossy147/monad-pattern
Monad pattern
2016-02-21 20:36:05 +02:00
9f086ba72c Merge pull request #382 from Crossy147/master
issue #333 Factory-kit
2016-02-21 19:56:53 +02:00
cfd83b5753 issue #333 review changes 2016-02-21 12:54:40 +01:00
81e8d354a9 issue #335 review changes 2016-02-21 12:10:08 +01:00
c580b61df3 Merge pull request #380 from DevFactory/release/Type-parameter-names-should-comply-with-a-naming-convention-fix-1
squid:S00119 - Type parameter names should comply with a naming conve…
2016-02-20 19:35:53 +02:00
9714fe075a Merge pull request #387 from DevFactory/release/Constructors-should-only-call-non-overridable-methods-fix-1
squid:S1699 - Constructors should only call non-overridable methods
2016-02-20 19:25:48 +02:00
bbd769b208 Merge pull request #386 from amitbhoraniya/master
Dao Pattern : Create object with reference to Interface
2016-02-20 18:34:47 +02:00
d3689b2040 squid:S00119 - Type parameter names should comply with a naming convention 2016-02-20 18:19:44 +02:00
ea81ef71ab Merge pull request #377 from iluwatar/FactoryMethodChanges
Factory and Abstract Factory changes
2016-02-20 17:49:14 +02:00
80ff7bb217 issue #335 brace typo 2016-02-20 15:01:45 +01:00
64f1fe8979 issue #335 typos fixed 2016-02-20 14:55:37 +01:00
f47b9283c3 Merge branch 'master' of https://github.com/iluwatar/java-design-patterns into monad-pattern 2016-02-19 19:10:43 +01:00
72e08365b8 issue #335 documentation improvements 2016-02-19 19:08:35 +01:00
3e526cb5da issue #335 Monad pattern introduced 2016-02-19 17:56:09 +01:00
50310aaeaf squid:S1699 - Constructors should only call non-overridable methods 2016-02-19 11:02:49 +02:00
b70614efef Creating object with reference to Interface
In Dao pattern DaoImpl object is created with reference to dao interface.
2016-02-19 00:10:55 +05:30
dfef28e93e Merge pull request #384 from DevFactory/release/Redundant-Field-Initializer-fix-1
pmd:RedundantFieldInitializer - Redundant-Field-Initializer
2016-02-18 12:39:06 +05:30
0003c6cb00 pmd:RedundantFieldInitializer - Redundant-Field-Initializer 2016-02-18 08:40:19 +02:00
6ab9b36d59 issue #333 javadocs changes 2016-02-17 19:35:10 +01:00
2fa705ab59 issue #333 snapshot version fixed 2016-02-16 00:05:28 +01:00
8fabc861b3 pom.xml minor 2016-02-15 21:57:26 +01:00
53fdaba6c4 Merge branch 'master' of https://github.com/iluwatar/java-design-patterns 2016-02-15 21:48:07 +01:00
8b625a8d3c issue #333 minor revert 2016-02-15 20:54:55 +01:00
022ab28e20 issue #333 diagrams and index added 2016-02-15 20:37:16 +01:00
f1122f78e3 Added real life application to Command pattern 2016-02-15 18:21:34 +05:30
cd077fa490 Merge branch 'master' of https://github.com/iluwatar/java-design-patterns into FactoryMethodChanges 2016-02-12 15:49:35 +05:30
823dc6395f Merge pull request #376 from DevFactory/release/Classes-without-public-constructors-should-be-final-fix-1
squid:S2974 - Classes without public constructors should be final
2016-02-12 15:44:31 +05:30
221b71781a Resolved checkstyle audit error 2016-02-11 12:29:35 +05:30
b5d4445d63 Made example App a bit easier to understand 2016-02-10 17:53:32 +05:30
f64ba22c64 1) Removed warning from test case. 2) Made implementation of App more understandable. 2016-02-10 17:38:15 +05:30
632174b6dc squid:S2974 - Classes without public constructors should be final 2016-02-09 17:19:31 +02:00
57be8aa522 Merge pull request #375 from DevFactory/release/The-members-of-an-interface-declaration-or-class-should-appear-in-a-pre-defined-order-fix-1
squid:S1213 - The members of an interface declaration or class should…
2016-02-08 20:40:16 +02:00
3cbb88e09c #297 Create unit tests for Gateway API pattern 2016-02-07 17:05:45 -06:00
88c3b04eb3 #297 Create API Gateway pattern 2016-02-07 17:05:33 -06:00
9c5745763d squid:S1213 - The members of an interface declaration or class should appear in a pre-defined order 2016-02-06 01:10:56 +02:00
1655f30845 Merge pull request #372 from DevFactory/release/Methods-should-not-be-empty-fix-1
squid:S1186 - Methods should not be empty
2016-02-05 21:07:57 +02:00
769a6206f2 Merge pull request #370 from fluxw42/license_date_2016
Update license year from 2014 to range '2014-2016'
2016-02-05 21:07:02 +02:00
9b6517453f Merge pull request #362 from JuhoKang/master
Value object pattern #349
2016-02-05 21:04:21 +02:00
df4a40fc13 squid:S1186 - Methods should not be empty 2016-02-03 21:51:40 +02:00
83533543e6 format code 2016-02-03 23:38:13 +09:00
f71e186959 Fixed descriptions in code. 2016-02-03 23:33:40 +09:00
db2140ecc9 updated child and parent pom 2016-02-03 23:02:27 +09:00
049841298e deleted the change in parent pom 2016-02-03 22:59:15 +09:00
1e5cbe1f76 Merge remote-tracking branch 'upstream/master' 2016-02-03 22:49:59 +09:00
53cc97e9d0 Update license year from 2014 to range '2014-2016' 2016-02-03 07:15:19 +01:00
33224dd7d7 Prepare for next development iteration 2016-02-02 22:14:20 +02:00
4f56f7b097 Achieved milestone 1.10.0 2016-02-02 22:11:38 +02:00
e25cbad811 Merge pull request #367 from mikulucky/master
Feature Toogle PR
2016-02-02 22:02:15 +02:00
6caea8557b added missing space, 'cause website didnt display correctly 2016-02-02 17:31:12 +01:00
d8378915a1 pom.xml change to fit upstream 2016-02-02 08:02:38 +09:00
0e7fae21c3 Edit pom.xml 2016-02-02 07:48:43 +09:00
3ef464986c Merge remote-tracking branch 'upstream/master', fixed f-c index properly 2016-02-02 07:35:06 +09:00
e05592b522 Merge pull request #365 from DevFactory/release/Append-Character-With-Char-fix-1
pmd:AppendCharacterWithChar - Append Character With Char
2016-02-01 22:28:34 +02:00
f08af14555 Merge pull request #364 from DevFactory/release/The-diamond-operator-should-be-used-fix-1
squid:S2293 - The diamond operator should be used
2016-02-01 22:26:43 +02:00
c7f4311706 #354 Clean up 2016-02-01 18:57:05 +00:00
37da470178 #354 Finish Readme 2016-02-01 18:45:54 +00:00
7adefc89ba pmd:AppendCharacterWithChar - Append Character With Char 2016-02-01 04:20:52 +02:00
b27d6dff66 Merge branch 'master' of github.com:mikulucky/java-design-patterns
terns
Update
2016-01-31 23:28:28 +00:00
bf5ba44260 #354 add App.java 2016-01-31 23:24:35 +00:00
8603333e5d #354 Adding Class Diagram 2016-01-31 14:10:34 +00:00
7cc93de672 #354 Merged Remote Master and resolved conflicts 2016-01-31 13:58:00 +00:00
c2e750aca1 #354 finished method javadocs 2016-01-31 13:46:34 +00:00
59c32d3937 Add tests that run the examples 2016-01-31 12:09:09 +02:00
dc4f07eb81 Merge pull request #360 from mikulucky/MIT-Source
Pull Request for adding License Plugin and Generate #358
2016-01-30 15:10:42 +02:00
d24a12a9b2 Merge pull request #359 from DevFactory/release/Local-Variables-should-not-be-declared-and-then-immediately-returned-or-thrown-fix-1
squid:S1488 - Local Variables should not be declared and then immedia…
2016-01-30 14:42:05 +02:00
62b2f8e9a4 Merge pull request #357 from DevFactory/release/Consecutive-Appends-Should-Reuse-fix-1
pmd:ConsecutiveAppendsShouldReuse - Consecutive Appends Should Reuse
2016-01-30 14:37:18 +02:00
409ff027b8 squid:S2293 - The diamond operator should be used 2016-01-29 07:33:34 +02:00
98326a1e5e #354 Start Adding Java docs 2016-01-28 21:14:40 +00:00
d3eb8a2ef2 Added comments in the code. modified index.md 2016-01-29 00:53:27 +09:00
083065ba93 Added index.md
Added index.md with explanation which seems a little bit short of detail.
Fixed the directory of the files.
2016-01-28 23:33:46 +09:00
cca40a543a Added Code 2016-01-28 22:39:50 +09:00
3d95696078 #358 Added license to all files using plugin 2016-01-27 22:20:42 +00:00
321f5d6c5a Merge branch 'master' of https://github.com/iluwatar/java-design-patterns into MIT-Source 2016-01-27 22:15:15 +00:00
7b61395bc1 #358 Add Plugin for Auto License 2016-01-27 22:14:28 +00:00
ab2aad3226 Work on #226, moved pattern specific references to respective patterns. And removed credits section from Home page. 2016-01-27 12:55:59 +05:30
4e40cc3888 squid:S1488 - Local Variables should not be declared and then immediately returned or thrown 2016-01-27 02:45:39 +02:00
77e14f0069 #354 Add tests for Properties 2016-01-26 23:38:28 +00:00
4a49f82f23 #354 add general boolean method to services for feature status. Change user.toString 2016-01-26 21:18:47 +00:00
ba1d3a0fbf #354 Added Configuration Based Example of Feature Toggle 2016-01-26 21:08:28 +00:00
d627b7af6b #354 Moved Tests to the correct area 2016-01-26 20:24:43 +00:00
91b2379fd0 #354 Fixed CheckStyle Issues 2016-01-26 19:20:28 +00:00
32f9cf3ab1 #354 Some clean up and show the difference between paid and free a bit more. 2016-01-26 18:58:35 +00:00
a1ede8980f #354 Added WelcomeMessage Service and Tests for tier example of featureToggle 2016-01-26 18:49:25 +00:00
72733acfc6 #354 added usergroup for version of feature toggle 2016-01-26 18:41:08 +00:00
d00bfae5ee pmd:ConsecutiveAppendsShouldReuse - Consecutive Appends Should Reuse 2016-01-26 19:58:45 +02:00
0b834128b9 #354 Add Blank index.md 2016-01-25 21:29:05 +00:00
89e0e3e73e #354 Remove generated copyright banner 2016-01-25 21:16:35 +00:00
d7526fc7c0 #354 Add maven model for feature toggle design pattern 2016-01-25 21:14:24 +00:00
cf10bd1d05 #354 Add maven model for feature toggle design pattern 2016-01-25 21:11:26 +00:00
5ad99be224 #354 Add maven model for feature toggle design pattern 2016-01-25 21:10:58 +00:00
64b89ecb59 Create project for value-object pattern 2016-01-23 10:06:57 +09:00
1a55f3a420 Work on #353: More descriptive Tags
* Added the full name for Apache Camel, including the trademark symbol for clarity among other things named "Camel" and to indicate that this is a 3rd party software
2016-01-19 21:28:54 +01:00
10bbf988ea issue #333 factory kit pattern introduced 2016-01-17 13:47:44 +01:00
bd82387fc1 Merge pull request #345 from azhuzhu/master
Fix the wrong uml .png name in decorator
2016-01-14 19:47:09 +02:00
3398badd30 Merge pull request #344 from hoswey/master
fix issue #343 ReaderWriterLock unit tests fail on CI
2016-01-14 19:42:46 +02:00
033dce8387 Fix the wrong uml .png name in decorator 2016-01-15 00:56:46 +08:00
e95cfe9292 fix issue #343 ReaderWriterLock unit tests fail on CI 2016-01-13 09:35:31 +08:00
150c4e0d5d Ignore rest of ReaderWriterLock tests with intermittent failures 2016-01-12 21:16:39 +02:00
c8db19efe2 Ignore another test with intermittent failures until fixed 2016-01-12 21:08:10 +02:00
2fec4f891b Ignore test with intermittent failures until fixed 2016-01-12 20:57:36 +02:00
adf131b784 Merge pull request #326 from hoswey/master
implements the #75 reader writer lock
2016-01-12 20:15:22 +02:00
77d45c35e0 implements the #75 reader writer lock, fix the problem of review 2016-01-10 21:23:52 +08:00
2f84369003 Merge remote-tracking branch 'upstream/master' 2016-01-09 22:26:18 +08:00
83f1ac7489 Update dependencies 2016-01-07 21:41:45 +02:00
03e187743c Merge pull request #340 from tomroy/master
Decorator pattern: SmartTroll should be SmartHostile #264
2016-01-06 19:44:26 +02:00
bd83fa28bb Correct method name and cleanup etc folder #264 2016-01-07 00:34:33 +08:00
30ca1ea1fb Decorator pattern: SmartTroll should be SmartHostile #264 2016-01-04 23:07:33 +08:00
4c5f9ae44c Merge pull request #339 from fluxw42/issue-238
Use headings instead of bold text in index.md #238

Script used to do it: https://gist.github.com/fluxw42/464820d08e3b567fda48
2016-01-04 02:15:37 +01:00
3d642cdad7 Use headings instead of bold text in index.md #238 2016-01-03 21:14:30 +01:00
b6beffec2e Merge pull request #299 from genericmethod/master
#113 Event-driven Architecture
2016-01-03 14:50:46 +02:00
1987bdb962 Merge pull request #1 from mikulucky/master
Class Diagram for EDA
2016-01-03 12:20:35 +00:00
bea1a0d6d9 Revert "Revert "Add class diagram for #113 and to be included in PR #299""
This reverts commit 0f75a0e239.
2016-01-03 00:55:04 +00:00
d6719729b9 Revert "Revert "Merge remote-tracking branch 'origin/master'""
This reverts commit 03f0a2112b.
2016-01-03 00:54:49 +00:00
03f0a2112b Revert "Merge remote-tracking branch 'origin/master'"
This reverts commit 248ea5191a, reversing
changes made to 02bd15db90.
2016-01-03 00:52:56 +00:00
0f75a0e239 Revert "Add class diagram for #113 and to be included in PR #299"
This reverts commit 0c062d3f55.
2016-01-03 00:52:24 +00:00
0c062d3f55 Add class diagram for #113 and to be included in PR #299 2016-01-03 00:01:43 +00:00
248ea5191a Merge remote-tracking branch 'origin/master' 2016-01-02 23:59:47 +00:00
39b183d569 Merge pull request #2 from genericmethod/master
Pull
2016-01-02 23:58:43 +00:00
02bd15db90 Merge remote-tracking branch 'iluwatar/master' 2016-01-02 18:39:58 +00:00
317a599c3b Merge pull request #337 from mikulucky/master
Provide a simple example for Callback Pattern using Lambdas
2016-01-02 19:04:43 +02:00
7176b86146 #113 Event Driven Architecture
bumped up version to 1.10
2016-01-02 14:05:36 +01:00
2ea9bfef19 #113 Event Driven Architecture
Fixed PMD errors
2016-01-02 14:04:07 +01:00
40042ae392 Merge remote-tracking branch 'iluwatar/master'
# Conflicts:
#	pom.xml
2016-01-02 11:48:01 +01:00
e25ef1b0f8 Check Style fixes #334 2016-01-02 00:54:26 +00:00
ca4a4ec07b Created a Lambdas example for the callback pattern, using the same output of the traditional version. Have also added another unit test for issue #334 2016-01-01 23:41:56 +00:00
e0e51324db Set version number for next development iteration 2016-01-01 20:39:20 +02:00
e4458c1b17 Achieved milestone 1.9.0 2016-01-01 20:37:50 +02:00
30e09a8dd9 Merge pull request #331 from fluxw42/master
Add unit tests for remaining patterns
2016-01-01 18:24:58 +02:00
f987c7253b Merge pull request #330 from mikulucky/master
Delegation Pattern
2016-01-01 16:49:01 +02:00
ad714294dd Clean up javaDocs on Printer.java #324 2015-12-30 20:08:52 +00:00
623c2081cd Update App.java to have more information on the pattern #324 2015-12-30 20:07:42 +00:00
542a832a66 Added tests for twin pattern 2015-12-30 20:55:22 +01:00
444eb07e26 Added tests for tolerant-reader pattern 2015-12-30 20:55:22 +01:00
fd8c05846f Added tests for thread-pool pattern
Fixed concurrency problem in id generation of Task
2015-12-30 20:55:22 +01:00
47709e24b9 Added tests for template-method pattern 2015-12-30 20:55:22 +01:00
09d3a82884 Added tests for visitor pattern 2015-12-30 20:55:22 +01:00
997bfba3b2 Added tests for strategy pattern 2015-12-30 20:55:22 +01:00
6326c1742d Added tests for step-builder pattern 2015-12-30 20:55:22 +01:00
2e2707862a Fixed checkstyle code quality issues 2015-12-30 20:55:21 +01:00
1d9aff4071 Added tests for state pattern 2015-12-30 20:55:21 +01:00
5611f26c77 Added tests for specification pattern 2015-12-30 20:55:21 +01:00
d0cdf84936 Added tests for singleton pattern 2015-12-30 20:55:21 +01:00
a375b2d28b Added tests for service-locator pattern
Fix NPE when requested service is unknown
2015-12-30 20:55:21 +01:00
fcfdbe71f5 Added tests for service-layer pattern 2015-12-30 20:55:21 +01:00
52c483f1d0 Added tests for servant pattern 2015-12-30 20:46:40 +01:00
c72faeb67e Added tests for resource-acquisition-is-initialization pattern 2015-12-30 20:46:40 +01:00
299d612b9b Added tests for proxy pattern 2015-12-30 20:46:40 +01:00
9d4c3154b1 Added tests for prototype pattern 2015-12-30 20:46:40 +01:00
a3b1265921 Added tests for property pattern 2015-12-30 20:46:40 +01:00
dca68511e8 Added tests for producer-consumer pattern 2015-12-30 20:46:40 +01:00
42a1dc69ca Added tests for private-class-data pattern 2015-12-30 20:46:40 +01:00
47e1cd710c Added tests for poison-pull pattern 2015-12-30 20:46:40 +01:00
b3d1c2b2ed Added tests for generic observer pattern 2015-12-30 20:46:40 +01:00
3e20a2afa8 Added tests for observer pattern 2015-12-30 20:46:39 +01:00
4c938ab8a5 Added tests for object-pool pattern 2015-12-30 20:46:39 +01:00
8f6f171a3f Added tests for null-object pattern 2015-12-30 20:46:39 +01:00
b4dcec45ef Added tests for multiton pattern 2015-12-30 20:46:39 +01:00
dec5ff22fc Update index.md #324 2015-12-30 18:26:32 +00:00
7b323e9cb4 Updated Class Diagram #324 2015-12-30 17:55:42 +00:00
a0af0a1a76 Merge pull request #325 from DevFactory/utility-classes-should-not-have-public-constructors-fix-3
Utility classes should not have public constructors
2015-12-30 19:55:25 +02:00
7c6e1fc3d8 Merge pull request #323 from DevFactory/code-quality-fix-5
Code quality fixes
2015-12-30 19:47:19 +02:00
45cecf68c4 Updated Class Diagram #324 2015-12-30 17:34:50 +00:00
d7580f5530 Review Comments #324 2015-12-30 16:56:47 +00:00
58b8a06561 Merge branch 'master' of https://github.com/iluwatar/java-design-patterns
* 'master' of https://github.com/iluwatar/java-design-patterns:
  Define checkstyle suppression filter location in maven plugin configuration
2015-12-30 16:17:07 +00:00
befe509582 Define checkstyle suppression filter location in maven plugin configuration 2015-12-30 17:58:03 +02:00
17b889c31d Update to match checkStyle rules added for test packages #324 2015-12-29 22:07:52 +00:00
52192de909 Merge commit '8b020837eaacc9ed4497f3c2461984935314bfb8' into add-delegation-pattern
* commit '8b020837eaacc9ed4497f3c2461984935314bfb8':
  Checkstyle corrections
  Checkstyle configuration to look into test classes too
  Rephrase readme title
  Corrected difficulty for Visitor #213
  Add performance tag to relevant patterns #213
  Categorize and tag all patterns #213
  Update CONTRIBUTING.MD
  Update CONTRIBUTING.MD
  add-contributing
2015-12-29 22:00:56 +00:00
8b020837ea Checkstyle corrections 2015-12-29 21:34:27 +02:00
b369812511 Checkstyle configuration to look into test classes too 2015-12-29 13:27:49 +02:00
52d6e20ad9 Readd File to Index#324 2015-12-28 22:13:05 +00:00
749880e3b9 Messed up indexes #324 2015-12-28 22:12:11 +00:00
41593774c6 CheckStyle reporting strange error about classname, suspect caching, forcing a clean build #324 2015-12-28 21:56:41 +00:00
0bc722f797 Fix CheckStyle #324 2015-12-28 20:34:28 +00:00
fcadb223ce Merge branch 'add-delegation-pattern'
* add-delegation-pattern:
  Add java documentation #324
  Populate the index.md for the delegate module #324
  Move App.java to correct Package #324
  Move App.java to correct Package #324
  Generic For AbstractPrinterController #324
  Generate UML for delegation pattern
  Add simple tests for delegate pattern #324
  Make AppTest.java match other patterns and update AppTest.java to match other patterns #324
  3am Code is starting to show. Get this build working. #324
  Created a unit test for build, added junit to pom for delegation maven module. #324
  Add template index.md for population later #324
  Added skeleton code for delegation pattern #324
  Create maven module for delegation pattern #324
2015-12-28 20:01:14 +00:00
c842f88eb7 Add java documentation #324 2015-12-28 19:23:00 +00:00
6d516d5124 Populate the index.md for the delegate module #324 2015-12-28 18:16:58 +00:00
9544dd321a Rephrase readme title 2015-12-28 20:09:53 +02:00
d623e9c8fd Corrected difficulty for Visitor #213 2015-12-28 19:52:10 +02:00
e27de33f75 Add performance tag to relevant patterns #213 2015-12-28 16:07:43 +02:00
7ac7e3b097 Categorize and tag all patterns #213 2015-12-28 15:52:44 +02:00
fefb51c46e Merge pull request #329 from zafarella/patch-1
add-contributing
2015-12-28 09:34:14 +02:00
58547fae8f Update CONTRIBUTING.MD
real fix :)
2015-12-27 22:44:15 -05:00
30676f8d4f Update CONTRIBUTING.MD
fix the typo
2015-12-27 22:42:42 -05:00
483db04cef Move App.java to correct Package #324 2015-12-27 20:12:04 +00:00
fac10dc454 Move App.java to correct Package #324 2015-12-27 20:10:48 +00:00
982f9f5e31 Generic For AbstractPrinterController #324 2015-12-27 20:09:33 +00:00
74d1823078 Merge pull request #1 from fluxw42/add-delegation-pattern
Generate UML for delegation pattern
2015-12-27 20:03:42 +00:00
f59f18091e Remove Coverity scan #327 2015-12-27 21:23:09 +02:00
5f033be54f Fix PMD violations #327 2015-12-27 21:21:57 +02:00
df911baf36 Added maven pmd plugin and configured it to fail build when violations are found #327 2015-12-27 21:21:31 +02:00
32e7181478 Generate UML for delegation pattern 2015-12-27 18:13:34 +01:00
c8a750df49 Fixing squid:S1118 - Utility classes should not have public constructors 2015-12-27 21:17:13 +05:00
191078735f Fixing squid:S1698 - Objects should be compared with equals() and squid:HiddenFieldCheck - Local variables should not shadow class fields 2015-12-27 21:12:35 +05:00
fa6a6006c3 add-contributing
so github will show link whenever PR are made
2015-12-27 11:03:21 -05:00
a49dbefb56 Add simple tests for delegate pattern #324 2015-12-27 14:10:49 +00:00
fb0617e9c5 Make AppTest.java match other patterns and update AppTest.java to match other patterns #324 2015-12-27 13:59:50 +00:00
84fd2348ea 3am Code is starting to show. Get this build working. #324 2015-12-26 23:02:45 +00:00
f0ff8ad4b3 Created a unit test for build, added junit to pom for delegation maven module. #324 2015-12-26 22:55:12 +00:00
c3184255bf Add template index.md for population later #324 2015-12-26 22:29:45 +00:00
bdacfe30c1 Added skeleton code for delegation pattern #324 2015-12-26 22:20:53 +00:00
30363cbb7f Create maven module for delegation pattern #324 2015-12-26 22:05:12 +00:00
3d8c64d76d Merge pull request #322 from DevFactory/dead-stores-fix-1
Fixing squid:S1854 - Dead stores should be removed
2015-12-26 13:38:16 +02:00
78fcd63271 Merge branch 'fluxw42-master' 2015-12-26 13:07:37 +02:00
30bc25b5bf Merge branch 'master' of https://github.com/fluxw42/java-design-patterns into fluxw42-master
Conflicts:
	monostate/src/main/java/com/iluwatar/monostate/LoadBalancer.java
2015-12-26 12:36:38 +02:00
6b1356a160 Add Gitter link to README.md 2015-12-26 12:12:33 +02:00
3731d26f6d implants the #75 reader writer lock 2015-12-26 14:17:24 +08:00
cec9a99410 Adjust checkstyle rules. Make checkstyle fail the build when violations are found. Correct all current checkstyle violations. 2015-12-25 23:49:28 +02:00
9fbb085985 Checkstyle fails the build when violations are detected 2015-12-23 13:20:39 +02:00
6e496e7c86 Fixing squid:S1854 - Dead stores should be removed 2015-12-23 13:41:38 +05:00
e3e0e32e92 Fixed failing unit test
LoadBalancer has several static fields, this could cause problems since
JUnit tests are executed concurrently.
2015-12-21 14:35:36 +01:00
531158c836 Added tests for monostate pattern 2015-12-21 13:29:25 +01:00
6fe01e73b2 Add additional tests for model-view-presenter pattern 2015-12-21 12:17:20 +01:00
69c9374669 Added tests for model-view-controller pattern 2015-12-20 14:31:36 +01:00
a57a71b09c Added tests for memento pattern 2015-12-20 10:39:02 +01:00
719f80a0d6 Added tests for mediator pattern 2015-12-20 00:00:07 +01:00
2c82bd9450 Added tests for lazy-loading pattern 2015-12-19 21:44:50 +01:00
5948a82cf2 Added tests for layers pattern 2015-12-19 21:44:50 +01:00
a0151826ad Changed page-index to 1 for a better structured navbar 2015-12-19 17:35:49 +01:00
33fe90d177 Merge pull request #317 from fluxw42/master
Added some more JUnit tests
2015-12-15 18:48:31 +02:00
25cacdbbc9 Added tests for iterator pattern 2015-12-14 15:14:48 +01:00
323e4c8751 Added tests for interpreter pattern 2015-12-14 12:46:07 +01:00
de78490d29 Added tests for intercepting-filter pattern 2015-12-13 15:18:13 +01:00
9059d2b96c Added proper tests for front-controller pattern 2015-12-13 13:58:39 +01:00
dbca06a9e7 Added proper tests for half-sync-half-async 2015-12-13 13:04:17 +01:00
ca14e8ddad Add proper tests for flyweight pattern 2015-12-13 11:42:25 +01:00
3dc370e2d1 Add proper tests for flux pattern 2015-12-12 22:43:47 +01:00
4181514c65 Add proper tests for fluent-interface pattern and fixed a little bug 2015-12-12 20:16:10 +01:00
df69a8f986 Add proper tests for execute-around pattern 2015-12-12 20:14:59 +01:00
885d5bb7dd Add proper unit tests for event-aggregator pattern 2015-12-12 20:13:25 +01:00
1b74e0ff67 Merge pull request #316 from fluxw42/master
Added more JUnit tests
2015-12-12 09:44:41 +02:00
94f80d1868 Add proper unit tests for composite pattern 2015-12-11 20:24:56 +01:00
c837ffe234 Add proper unit tests for double-dispatch pattern 2015-12-11 20:24:56 +01:00
2edc1898b1 Add proper unit tests for double-checked-locking pattern 2015-12-11 20:24:56 +01:00
29fc56002a Add proper unit tests for dependency-injection pattern 2015-12-11 20:24:56 +01:00
0643289c74 Dependency org.mockito:mockito-core should have scope 'test' 2015-12-11 20:24:56 +01:00
2c0a5e8703 Add proper unit tests for facade pattern 2015-12-11 20:24:56 +01:00
a3372febd0 Merge pull request #315 from Deses/master
Just  Just a quick fix for the Front-controller pattern.
2015-12-11 20:46:18 +02:00
7df65adbfc Just Just a quick fix for the Front-controller pattern. 2015-12-11 13:54:32 +01:00
d7dd8d42af Merge pull request #312 from fluxw42/master
Add proper unit tests for chain, bridge and builder pattern #293
2015-12-09 20:23:51 +02:00
4e7a8fdaca Merge pull request #314 from iluwatar/fstrategy
Functional approach to Strategy pattern #310
2015-12-08 23:27:01 +02:00
6e59d9554f Functional approach to Strategy pattern #310 2015-12-08 23:25:05 +02:00
e85308fbc4 Merge pull request #309 from JuhoKang/adapterdev
Attempt to solve issue #292
2015-12-08 20:53:15 +02:00
10a94cc91c Add proper unit tests for decorator pattern 2015-12-07 20:37:27 +01:00
e2d8079b36 Fixed code to follow coding conventions 2015-12-07 10:35:32 +09:00
8367c83aca Add proper unit tests for bridge pattern #293 2015-12-06 23:48:48 +01:00
875e5b872c Add proper unit tests for builder pattern #293 2015-12-06 23:14:07 +01:00
1fa617d08d Add proper unit tests for chain pattern #293 2015-12-06 22:58:16 +01:00
6c1f025d0f Apply code formatting rules to async-method-invocation example tests 2015-12-06 21:42:06 +02:00
601964a2d1 Merge pull request #311 from fluxw42/master
Add proper unit tests for async-method-invocation #293
2015-12-06 21:33:03 +02:00
1884df525b Add proper unit tests for async-method-invocation #293 2015-12-06 13:43:01 +01:00
507b89d5e4 Apply project coding conventions to Repository example 2015-12-05 21:26:30 +02:00
02d6754804 Merge pull request #308 from neonds/spring-annotation-config
Annotation Config was added.
2015-12-05 21:12:12 +02:00
e709a196bd Set version number for next development iteration 2015-12-02 23:26:07 +02:00
f018d13c39 Set version number for monthly release 2015-12-02 23:21:44 +02:00
33b41f872e The new java files was not added.. #292 2015-12-02 18:45:08 +09:00
898f3a428c #113 Event Driven Architecture
Fixed a typo in index.md
2015-12-02 01:43:34 +01:00
0b46a9985d #113 Event Driven Architecture
Updated index.md with eda uses
2015-12-02 01:39:20 +01:00
2aa20b7445 #113 Event Driven Architecture
Adds various changes including :
- Fixes to Javadoc
2015-12-01 23:33:26 +01:00
cfb0fafc7d #113 Event Driven Architecture
Adds various changes including :
- Fixes to Javadoc
- Test refactoring and improvements
- Refactored EventDispatcher to be immutable
- Removed DynamicRouter interface since it not needed
- Renamed Channel to a more appropriate name - Handler
2015-12-01 23:30:01 +01:00
119d264779 issue #292 2015-12-01 16:00:31 +09:00
9e857d7dd6 #113 Event Driven Architecture
Fixed javadoc
2015-11-28 19:05:23 +01:00
d9a1d1cef9 #113 Event Driven Architecture
Adds unit test to assert and verify pattern event get type behaviour.
Also added unit test comments.
2015-11-28 17:58:32 +01:00
3ad36020aa #113 Event Driven Architecture
Adds unit test to assert and verify pattern behaviour
2015-11-28 17:25:15 +01:00
e1c0731f7e #113 Event Driven Architecture
Adds more Javadoc and fixes checkstyle issues.
2015-11-28 15:03:22 +01:00
b8b94b697a #113 Event Driven Architecture
Adds more Javadoc
2015-11-28 13:12:16 +01:00
fc70a706c6 #113 Event Driven Architecture
Adds module to the root pom.xml
Fixes indentation
2015-11-28 10:57:00 +01:00
9a85dfe9df Annotation Config was added. Now AppConfig contains a Main Method (same logic in App.java) to execute 2015-11-27 21:23:55 -06:00
5bec63659f Merge pull request #305 from hoswey/master
Fix #216 Repository vs DAO
2015-11-28 00:09:27 +02:00
9d4fff6029 Fix #216 Repository vs DAO 2015-11-27 11:22:33 +08:00
321e9d4191 #113 Event Driven Architecture
- added class diagram
- added more comments
2015-11-23 11:20:20 +01:00
b4aeca3aa0 #113 Event Driven Architecture
- removed unused imports
2015-11-23 00:04:44 +01:00
3ef0921f20 #113 Event Driven Architecture
- refactored and moved around some classes
2015-11-23 00:02:58 +01:00
eb396217d0 #113 Event Driven Architecture
- initial commit includes a simple and advanced example of Event-driven architecture
2015-11-22 19:40:07 +01:00
092d48d150 Merge pull request #294 from DevFactory/release1
Unit tests for adapter, business-delegate, factory-method and command modules
2015-11-22 08:44:13 +02:00
6b99f2669e Added capability for test coverage report generation and steps to do so. 2015-11-22 05:47:36 +05:30
ced317bc9d Added UnitTest cases for factory method. 2015-11-22 05:46:14 +05:30
e5614e5a20 Added UnitTest cases for command. 2015-11-22 05:45:45 +05:30
012b638023 Added UnitTest cases for business delegate. 2015-11-22 05:45:14 +05:30
b577890db4 Added UnitTest cases for adapter. 2015-11-22 05:44:45 +05:30
8ba0192864 Add EIP tag to relevant patterns 2015-11-21 16:34:59 +02:00
899b9617c9 Merge pull request #295 from iluwatar/JaXt0r-publish-subscribe
Jaxt0r publish subscribe
2015-11-21 16:10:34 +02:00
d0fca6d318 Improve the example and documentation 2015-11-21 16:05:55 +02:00
7885380633 Apply Google coding conventions 2015-11-21 15:12:31 +02:00
230c02fb24 Fix spelling 2015-11-21 15:09:23 +02:00
b97e9207a7 Update version number for Publish-Subscribe 2015-11-21 15:03:27 +02:00
8519e13de6 Merge branch 'publish-subscribe' of https://github.com/JaXt0r/java-design-patterns into JaXt0r-publish-subscribe
Conflicts:
	pom.xml
2015-11-21 14:55:02 +02:00
ba3f583467 Merge pull request #290 from hoswey/master
implements Twin design pattern #63
2015-11-16 21:09:41 +02:00
142274f3f7 implements Twin design pattern #63, add credit and rephrase the comments 2015-11-16 10:01:03 +08:00
5b06c52fff Merge pull request #291 from tainarareis/abstract-factory
Issue #286: Added main method in Abstract Factory Example
2015-11-14 21:33:48 +02:00
033f8e740d Merge pull request #287 from l-cortese/master
log4j.xml relocated and excluded from JAR
2015-11-14 21:19:50 +02:00
34528173b7 Issue #286: Added main method in Abstract Factory Example 2015-11-14 16:48:19 -02:00
fdbfa9e8ee implements Twin design pattern #63 2015-11-14 17:38:35 +08:00
bf65168776 corrected typos in the comments 2015-11-13 22:35:30 +01:00
043a610754 log4j.xml relocated due to visibility issues and excluded from generated
JAR. pom.xml formatted according to coding conventions
2015-11-13 18:34:10 +01:00
27199325ec Merge pull request #284 from hoswey/master
correct the package name for producer-consumer test folder
2015-11-07 11:48:51 +02:00
960b568fbb correct the package name for producer-consumer test folder 2015-11-07 15:51:16 +08:00
c02e65fa3a Added alias names for GOF patterns #267 2015-11-04 21:13:32 +02:00
fe63c9cec4 Merge pull request #281 from ankurkaushal/master
Reformat according to google style guide
2015-11-02 21:39:17 +02:00
7e4f04602e Merge pull request #282 from l-cortese/master
Corrected Freddy's last name
2015-11-02 21:36:20 +02:00
306b1f3d31 Reformat rest of the design patterns - Issue #224 2015-11-01 21:29:13 -05:00
449340bd2b Reformat business-delegate, callback, chain, command, composite, dao, decorator & dependency-injection patterns. 2015-11-01 18:48:43 -05:00
3af06a3a3a Reformat builder pattern - issue #224 2015-11-01 18:03:29 -05:00
e7b6542134 Reformat bridge design pattern - Issue #224 2015-11-01 17:43:54 -05:00
16a8c85af6 Reformat Async Method Invocation - Issue #224 2015-11-01 17:33:25 -05:00
95c16200e7 Reformat Adapter Pattern - Issue #224 2015-11-01 17:26:57 -05:00
c0c21ebd91 Reformat Abstract Factory - Issue #224 2015-11-01 17:18:39 -05:00
25c1f87d46 Corrected Freddy's second name 2015-11-01 23:15:57 +01:00
c6ca80b25f Bump version number for the next development iteration 2015-11-01 22:22:31 +02:00
a2dd87d28d Merge pull request #277 from waisuan/master
Issue #273: Caching Patterns [new pattern]
2015-11-01 22:12:35 +02:00
998ba7e6e0 Issue #273: Fixed HTML tags in comments 2015-11-02 02:11:58 +08:00
6418a6c2b6 Issue #273: Fixed issues based on review remarks 2015-11-02 01:40:38 +08:00
37cfa4b295 Merge remote-tracking branch 'upstream/master' 2015-11-02 01:38:37 +08:00
7d3483daad Merge pull request #280 from ankurkaushal/master
Reformat Code According to Google Style Guide #224
2015-11-01 17:57:14 +02:00
44b7b94da6 Reformatting test case as well 2015-11-01 02:23:27 -05:00
87baa98d2b Reformat Code According to Google Style Guide #224 2015-11-01 02:05:54 -05:00
3dc9b2f97e Merge pull request #276 from hoswey/master
#271 implements producer-consumer
2015-10-31 19:02:03 +02:00
d0f5009996 Issue #273: Changed DB to internal Java data structure to avoid compilation errors + decrease in code coverage 2015-10-29 00:57:41 +08:00
9891c2e17b Issue #273:Caching Patterns [new pattern] 2015-10-28 23:55:47 +08:00
07faa2f625 #271 implements producer-consumer 2015-10-28 09:55:05 +08:00
a869294851 Merge pull request #257 from mafagafogigante/readme-warning-for-beginners
A Warning for beginners in the Readme.
2015-10-25 08:47:49 +02:00
ac5c1967df #161 - Publish Subscribe Channel realisation.Heavily based on iluwatars Message Channel implementation (#143). 2015-10-25 07:11:34 +01:00
a2b8359ab5 Merge pull request #269 from iamrichardjones/master
Add unit test to callback method
2015-10-20 23:37:39 +03:00
21a4d7b4c9 Add unit test to show that the callback method is called. 2015-10-19 22:07:00 +01:00
83c2fbdcd3 Add unit test to show that the callback method is called. 2015-10-19 22:06:35 +01:00
8eff279233 Merge pull request #263 from iamrichardjones/master
Update to singleton unit tests and lazy loading unit test
2015-10-19 21:21:45 +03:00
b961c57919 Merge pull request #268 from iluwatar/themoffster-master
Themoffster master - unit test improvements
2015-10-19 21:14:58 +03:00
b028f66b08 Removed properties 2015-10-19 21:01:41 +03:00
339db2a0bf Merge branch 'master' of https://github.com/themoffster/java-design-patterns into themoffster-master
Conflicts:
	dao/pom.xml
2015-10-19 20:44:46 +03:00
9cbc4a20b9 Merge pull request #265 from mkobit/double-checked-locking-executor-service-shutdown
Fix - Shutdown the ExecutorService in App so that the resources are c…
2015-10-14 20:10:46 +03:00
07a77ba11d Fix - Shutdown the ExecutorService in App so that the resources are collected and the process can finish
I ran App.main(String[] args) in the 'double-checked-locking' module and the process does not terminate. This is because the executor service still has open threads. I'm not sure how the JUnit tests are run, but it seems they are handling the leftover resources themselves.

Also, minor modifications to Inventory for final fields are used since there is no state change around them, and added some more meaningful printing so the example is more clearly demonstrated
2015-10-14 07:01:15 -05:00
e09dda6037 A Warning for beginners in the Readme. 2015-10-14 06:41:32 -03:00
7ab799c452 Synchronise the list as multiple threads are calling it 2015-10-13 21:23:32 -03:00
3c8b83748a Merge pull request #258 from amit2103/master
MonoState Pattern
2015-10-13 20:03:45 +03:00
5d970438bf Update comment 2015-10-12 05:22:09 -03:00
0d068a35d8 Update comment 2015-10-12 05:21:33 -03:00
64e3e1a9e8 For some reason it thinks there are two fields in the CI build. Making this more generic 2015-10-11 22:16:51 -03:00
31e2940eb1 Remove error unit test so pull request can proceed. Will check this at at later date 2015-10-11 22:11:03 -03:00
0107b24976 Fix unit test by makinig getField use the field name directly 2015-10-11 22:06:00 -03:00
7cf5b32086 Add additional unit tests to show how lazy loading is working with reflection 2015-10-11 21:58:13 -03:00
45b0ac386e Add additional unit tests to show that singletons can be created in single thread environment and multithread environment. Also add a test to demonstrate a whole with Singleton when instantiating using reflection
Add some logging. Tests pass locally but not on github?
2015-10-11 21:54:45 -03:00
6ba7f5ea04 Add additional unit tests to show that singletons can be created in single thread environment and multithread environment. Also add a test to demonstrate a whole with Singleton when instantiating using reflection 2015-10-11 21:32:51 -03:00
271ce09e26 Fixed POMS 2015-10-09 23:26:10 +05:30
9d0673af0a Made changes according to feedback issue #258 2015-10-09 23:23:34 +05:30
eb22febdfc Printing Server variables 2015-10-09 23:23:34 +05:30
9a824c7d21 MonoState #85 2015-10-09 23:23:34 +05:30
81b5bc99ce Update Pom.xml
Fixed Reference to Parent POM
2015-10-08 09:43:19 +05:30
19f5966cb9 Added Comments and Feedback 2015-10-07 20:37:45 +05:30
1e988c10f9 fixed merge conflict 2015-10-07 20:10:36 +05:30
2c45f73254 MonoState #85 2015-10-04 03:12:51 +05:30
c8fd9f3a0d Monostate pattern #85 2015-10-04 03:06:11 +05:30
0a9879a277 Improve Strategy Javadoc 2015-10-04 00:22:27 +03:00
2234a25c76 Improve State Javadoc 2015-10-04 00:19:34 +03:00
74e32259be Improve Service Locator Javadoc 2015-10-04 00:16:05 +03:00
8db2bb2ac8 Improve Servant Javadoc 2015-10-04 00:13:08 +03:00
c3a827b475 Improved Proxy Javadoc 2015-10-04 00:08:34 +03:00
9a4f83e7b8 Improve Prototype Javadoc 2015-10-04 00:04:12 +03:00
40e378c1f3 Improve Property Javadoc 2015-10-03 23:57:17 +03:00
98aa28d94e Improve Poison Pill Javadoc 2015-10-03 23:53:09 +03:00
4d1aae21f7 Improve Observer Javadoc 2015-10-03 23:48:51 +03:00
ca6bb7a3a8 Improve Memento Javadoc 2015-10-03 23:38:37 +03:00
fc66ae8084 Improve Mediator Javadoc 2015-10-03 23:34:20 +03:00
e4ff39e080 Improve Iterator Javadoc 2015-10-03 21:37:29 +03:00
44d7be9c94 Improve Interpreter Javadoc 2015-10-03 21:32:56 +03:00
b4118bb866 Improve Intercepting Filter Javadoc 2015-10-03 21:28:17 +03:00
c27291fd27 Improve Fluent Interface Javadoc 2015-10-03 21:17:56 +03:00
c989f6cb21 Improve Factory Method Javadoc 2015-10-03 21:14:40 +03:00
516b127d21 Improved Facade Javadoc 2015-10-03 21:11:19 +03:00
584a22238d Improve Event Aggregator Javadoc 2015-10-03 21:06:52 +03:00
e32b440a38 Improve Double Checked Locking Javadoc 2015-10-03 21:00:21 +03:00
8cf35fc315 Improve Decorator Javadoc 2015-10-03 20:43:38 +03:00
621793ed2d Improved DAO Javadoc 2015-10-03 20:34:15 +03:00
807478ab3d Improve Composite Javadoc 2015-10-03 20:27:28 +03:00
d5f52edecf Improve Command Javadoc 2015-10-03 20:21:56 +03:00
a2f3d58709 Improve Chain Javadoc 2015-10-03 20:19:01 +03:00
9a08e35101 Improve Builder Javadoc 2015-10-03 17:13:38 +03:00
cdd586ec7c Improve Bridge Javadoc 2015-10-03 12:40:24 +03:00
8c6caa29b7 Improve Adapter Javadoc 2015-10-03 11:56:59 +03:00
0a61d7b067 Improve Abstract Factory Javadocs 2015-10-03 11:53:44 +03:00
6413c4d2be Added more Singleton documentation #188 2015-10-02 22:53:41 +03:00
11cdd20f6f Update version to 1.7.0 2015-09-30 22:36:01 +03:00
621c3498f6 Remove broken deploy config #255 2015-09-26 22:52:59 +03:00
83fed6dd34 Fix Travis config syntax #255 2015-09-26 22:14:36 +03:00
793b1cc172 Travis configuration changes #255 2015-09-26 22:08:23 +03:00
2ad361f2c3 Travis configuration changes #255 2015-09-26 21:23:00 +03:00
e077aa34d7 Travis deploy web site to S3 2015-09-26 20:19:39 +03:00
c1fda3ad6c Merge pull request #254 from zafarella/refactor-singleton-according-to-checkstyle
Refactor singleton according to checkstyle rules
2015-09-24 22:32:11 +03:00
60f9b71278 eliminate all warnings of checkstyle. 2015-09-24 13:29:39 -04:00
ba6511fe5d Work on #226, moved POSA reference and some J2EE design pattern references 2015-09-24 12:23:02 +05:30
36809537d9 checkstyle fixes - docs, indent etc 2015-09-24 01:01:51 -04:00
6735c81b52 Merge pull request #253 from mgalushka/master
#247 adding getAttackPower method to pattern decorator
2015-09-23 21:10:35 +03:00
ec9af416ba #247 adding getAttackPower method to pattern decorator 2015-09-23 17:58:58 +01:00
b3e4e8a47b Work on #226, #213, added references of Gang Of Four to all GoF patterns, added tag for Gang Of Four, added difficulty tags to some of them 2015-09-22 18:25:56 +05:30
d0af12b1ee Removed magic number. 2015-09-16 21:32:52 +01:00
51dca28fe7 Updated unit .equals() and .hashCode() methods
Formatted code using this formatter:
https://github.com/google/styleguide/blob/gh-pages/eclipse-java-google-style.xml
Removed argument final declaration on interface
Updated addCustomer logic for cases where the added customer already
exists
2015-09-14 21:22:33 +01:00
9c43827004 Removed erroneous semi-colon. 2015-09-05 22:00:27 +01:00
3da48d970c Inclusion of log4j dependency rather than relying on
System.out.println() statements.
Added unit tests for doa module.
2015-09-05 21:54:14 +01:00
1587 changed files with 81793 additions and 12530 deletions

34
.gitignore vendored
View File

@ -1,14 +1,20 @@
target
.metadata
.settings
.classpath
.project
*.class
# Package Files #
*.jar
*.war
*.ear
.idea
*.iml
*.swp
datanucleus.log
target
.metadata
.settings
.classpath
.project
*.class
# Package Files #
*.jar
*.war
*.ear
.idea
*.iml
*.swp
datanucleus.log
/bin/
/bin/
/bin/
*.log
data-mapper/src/main/resources/log4j.xml
event-sourcing/Journal.json

View File

@ -1,20 +1,39 @@
language: java
jdk:
- oraclejdk8
- oraclejdk8
env:
global:
- GH_REF: github.com/iluwatar/java-design-patterns.git
- secure: "LxTDuNS/rBWIvKkaEqr79ImZAe48mCdoYCF41coxNXgNoippo4GIBArknqtv+XvdkiuRZ1yGyj6pn8GU33c/yn+krddTUkVCwTbVatbalW5jhQjDbHYym/JcxaK9ZS/3JTeGcWrBgiPqHEEDhCf26vPZsXoMSeVCEORVKTp1BSg="
before_install:
- "export DISPLAY=:99.0"
- "sh -e /etc/init.d/xvfb start"
- secure: LxTDuNS/rBWIvKkaEqr79ImZAe48mCdoYCF41coxNXgNoippo4GIBArknqtv+XvdkiuRZ1yGyj6pn8GU33c/yn+krddTUkVCwTbVatbalW5jhQjDbHYym/JcxaK9ZS/3JTeGcWrBgiPqHEEDhCf26vPZsXoMSeVCEORVKTp1BSg=
- secure: "eoWlW9GyTJY04P8K3pxayXwU9/hmptQg/LfirispQkV9YvmziCfSzXnatnBhNfud98sCzY8BScXnb+OWLTnjLKpId4rtEqb0aJ40Jc32cUKzgzFAUn7cNcDAbUIfyPAGVqyQqfj/11wYSADwWMMOPlW97ExUtoyiH2WenXuRHso="
after_success:
- mvn clean test jacoco:report coveralls:report
- bash update-ghpages.sh
before_install:
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
# Migration to container-based infrastructure
sudo: false
# default install command is just "mvn install -DskipTests=true -Dmaven.javadoc.skip=true -B -V"
install:
- mvn install -DskipTests=true -Dmaven.javadoc.skip=true -B -V -e
after_success:
- mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent package sonar:sonar -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=$SONAR_TOKEN
- bash update-ghpages.sh
# use latest java version available instead of travis default
addons:
apt:
packages:
- oracle-java8-installer
notifications:
email:
- iluwatar@gmail.com
webhooks:
urls:
- https://webhooks.gitter.im/e/3319623945358a093a6f
on_success: change # options: [always|never|change] default: always
on_failure: always # options: [always|never|change] default: always
on_start: never # options: [always|never|change] default: always
sudo: required

13
CODE_COVERAGE.md Normal file
View File

@ -0,0 +1,13 @@
# Code Coverage Report generation
To generate the code coverage report, execute the following command:
> mvn clean verify jacoco:report
This will generate code coverage report in each of the modules. In order to view the same, open the following file in your browser.
> target/site/jacoco/index.html
Please note that the above folder is created under each of the modules. For example:
* adapter/target/site/jacoco/index.html
* busniess-delegate/target/site/jacoco/index.html

4
CONTRIBUTING.MD Normal file
View File

@ -0,0 +1,4 @@
This is great you have something to contribute!
Before going any further please read the [wiki](https://github.com/iluwatar/java-design-patterns/wiki)
with conventions and rules we used for this project.

View File

@ -1,6 +1,6 @@
The MIT License (MIT)
Copyright (c) 2014 Ilkka Seppälä
Copyright (c) 2014-2016 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

15
PULL_REQUEST_TEMPLATE.md Normal file
View File

@ -0,0 +1,15 @@
Pull request title
- Clearly and concisely describes what it does
- Refer to the issue that it solves, if available
Pull request description
- Describes the main changes that come with the pull request
- Any relevant additional information is provided
> For detailed contributing instructions see https://github.com/iluwatar/java-design-patterns/wiki/01.-How-to-contribute

View File

@ -2,12 +2,13 @@
that smart and dearly wants an empty line before a heading to be able to
display it as such, e.g. website) -->
# Design pattern samples in Java
# Design patterns implemented in Java
[![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)
[![Coverity Scan Build Status](https://scan.coverity.com/projects/5634/badge.svg)](https://scan.coverity.com/projects/5634)
[![License MIT](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/iluwatar/java-design-patterns/master/LICENSE.md)
[![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)
[![Quality Gate](https://sonarcloud.io/api/project_badges/measure?project=com.iluwatar%3Ajava-design-patterns&metric=alert_status)](https://sonarcloud.io/dashboard/index/com.iluwatar%3Ajava-design-patterns)
[![CII Best Practices](https://bestpractices.coreinfrastructure.org/projects/1503/badge)](https://bestpractices.coreinfrastructure.org/projects/1503)
# Introduction
@ -23,10 +24,16 @@ are familiar with the patterns.
# Getting started
Before you dive into the material, you should be familiar with various
[Programming/Software Design Principles](http://webpro.github.io/programming-principles/).
Before you dive into the material, you should be familiar with various
Programming/Software Design Principles.
Once you are familiar with these concepts you can start drilling down into patterns by any of the following approaches
All designs should be as simple as possible. You should start with KISS, YAGNI,
and Do The Simplest Thing That Could Possibly Work principles. Complexity and
patterns should only be introduced when they are needed for practical
extensibility.
Once you are familiar with these concepts you can start drilling down into
patterns by any of the following approaches
- Using difficulty tags, `Difficulty-Beginner`, `Difficulty-Intermediate` & `Difficulty-Expert`.
- Using pattern categories, `Creational`, `Behavioral` and others.
@ -34,21 +41,7 @@ Once you are familiar with these concepts you can start drilling down into patte
# How to contribute
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).
# Credits
* [Design Patterns: Elements of Reusable Object-Oriented Software](http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612)
* [Effective Java (2nd Edition)](http://www.amazon.com/Effective-Java-Edition-Joshua-Bloch/dp/0321356683)
* [Java Generics and Collections](http://www.amazon.com/Java-Generics-Collections-Maurice-Naftalin/dp/0596527756/)
* [Let's Modify the Objects-First Approach into Design-Patterns-First](http://edu.pecinovsky.cz/papers/2006_ITiCSE_Design_Patterns_First.pdf)
* [Pattern Languages of Program Design](http://www.amazon.com/Pattern-Languages-Program-Design-Coplien/dp/0201607344/ref=sr_1_1)
* [Presentation Tier Patterns](http://www.javagyan.com/tutorials/corej2eepatterns/presentation-tier-patterns)
* [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)
* [Patterns of Enterprise Application Architecture](http://www.amazon.com/Patterns-Enterprise-Application-Architecture-Martin/dp/0321127420)
* [Spring Data](http://www.amazon.com/Spring-Data-Mark-Pollack/dp/1449323952/ref=sr_1_1)
* [J2EE Design Patterns](http://www.amazon.com/J2EE-Design-Patterns-William-Crawford/dp/0596004273/ref=sr_1_2)
* [Pattern Oriented Software Architecture Vol I-V](http://www.amazon.com/Pattern-Oriented-Software-Architecture-Volume-Patterns/dp/0471958697)
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). We will help you and answer your questions in the [Gitter chatroom](https://gitter.im/iluwatar/java-design-patterns).
# License

View File

@ -0,0 +1,29 @@
---
layout: pattern
title: Abstract Document
folder: abstract-document
permalink: /patterns/abstract-document/
categories: Structural
tags:
- Java
- Difficulty-Intermediate
---
## Intent
Achieve flexibility of untyped languages and keep the type-safety
![alt text](./etc/abstract-document.png "Abstract Document Traits and Domain")
## Applicability
Use the Abstract Document Pattern when
* there is a need to add new properties on the fly
* you want a flexible way to organize domain in tree like structure
* you want more loosely coupled system
## Credits
* [Wikipedia: Abstract Document Pattern](https://en.wikipedia.org/wiki/Abstract_Document_Pattern)
* [Martin Fowler: Dealing with properties](http://martinfowler.com/apsupp/properties.pdf)

Binary file not shown.

After

Width:  |  Height:  |  Size: 94 KiB

View File

@ -0,0 +1,142 @@
<?xml version="1.0" encoding="UTF-8"?>
<class-diagram version="1.2.2" icons="true" always-add-relationships="false" generalizations="true" realizations="true"
associations="true" dependencies="false" nesting-relationships="true" router="FAN">
<class id="1" language="java" name="com.iluwatar.abstractdocument.AbstractDocument" project="abstract-document"
file="/abstract-document/src/main/java/com/iluwatar/abstractdocument/AbstractDocument.java" binary="false"
corner="BOTTOM_RIGHT">
<position height="-1" width="-1" x="659" y="286"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/>
</display>
</class>
<interface id="2" language="java" name="com.iluwatar.abstractdocument.Document" project="abstract-document"
file="/abstract-document/src/main/java/com/iluwatar/abstractdocument/Document.java" binary="false"
corner="BOTTOM_RIGHT">
<position height="-1" width="-1" x="562" y="27"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/>
</display>
</interface>
<class id="3" language="java" name="com.iluwatar.abstractdocument.domain.Car" project="abstract-document"
file="/abstract-document/src/main/java/com/iluwatar/abstractdocument/domain/Car.java" binary="false"
corner="BOTTOM_RIGHT">
<position height="-1" width="-1" x="348" y="737"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/>
</display>
</class>
<class id="4" language="java" name="com.iluwatar.abstractdocument.domain.Part" project="abstract-document"
file="/abstract-document/src/main/java/com/iluwatar/abstractdocument/domain/Part.java" binary="false"
corner="BOTTOM_RIGHT">
<position height="-1" width="-1" x="760" y="746"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/>
</display>
</class>
<interface id="5" language="java" name="com.iluwatar.abstractdocument.domain.HasModel" project="abstract-document"
file="/abstract-document/src/main/java/com/iluwatar/abstractdocument/domain/HasModel.java" binary="false"
corner="BOTTOM_RIGHT">
<position height="-1" width="-1" x="355" y="297"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/>
</display>
</interface>
<interface id="6" language="java" name="com.iluwatar.abstractdocument.domain.HasParts" project="abstract-document"
file="/abstract-document/src/main/java/com/iluwatar/abstractdocument/domain/HasParts.java" binary="false"
corner="BOTTOM_RIGHT">
<position height="-1" width="-1" x="109" y="297"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/>
</display>
</interface>
<interface id="7" language="java" name="com.iluwatar.abstractdocument.domain.HasPrice" project="abstract-document"
file="/abstract-document/src/main/java/com/iluwatar/abstractdocument/domain/HasPrice.java" binary="false"
corner="BOTTOM_RIGHT">
<position height="-1" width="-1" x="1008" y="283"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/>
</display>
</interface>
<interface id="8" language="java" name="com.iluwatar.abstractdocument.domain.HasType" project="abstract-document"
file="/abstract-document/src/main/java/com/iluwatar/abstractdocument/domain/HasType.java" binary="false"
corner="BOTTOM_RIGHT">
<position height="-1" width="-1" x="1257" y="277"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/>
</display>
</interface>
<realization id="9">
<end type="SOURCE" refId="4"/>
<end type="TARGET" refId="8"/>
</realization>
<realization id="10">
<end type="SOURCE" refId="3"/>
<end type="TARGET" refId="7"/>
</realization>
<generalization id="11">
<end type="SOURCE" refId="6"/>
<end type="TARGET" refId="2"/>
</generalization>
<realization id="12">
<end type="SOURCE" refId="4"/>
<end type="TARGET" refId="5"/>
</realization>
<realization id="13">
<end type="SOURCE" refId="4"/>
<end type="TARGET" refId="7"/>
</realization>
<generalization id="14">
<end type="SOURCE" refId="3"/>
<end type="TARGET" refId="1"/>
</generalization>
<realization id="15">
<end type="SOURCE" refId="3"/>
<end type="TARGET" refId="6"/>
</realization>
<generalization id="16">
<end type="SOURCE" refId="8"/>
<end type="TARGET" refId="2"/>
</generalization>
<generalization id="17">
<end type="SOURCE" refId="7"/>
<end type="TARGET" refId="2"/>
</generalization>
<realization id="18">
<end type="SOURCE" refId="3"/>
<end type="TARGET" refId="5"/>
</realization>
<generalization id="19">
<end type="SOURCE" refId="4"/>
<end type="TARGET" refId="1"/>
</generalization>
<generalization id="20">
<end type="SOURCE" refId="5"/>
<end type="TARGET" refId="2"/>
</generalization>
<realization id="21">
<end type="SOURCE" refId="1"/>
<end type="TARGET" refId="2"/>
</realization>
<classifier-display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/>
</classifier-display>
<association-display labels="true" multiplicity="true"/>
</class-diagram>

47
abstract-document/pom.xml Normal file
View File

@ -0,0 +1,47 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
The MIT License
Copyright (c) 2014-2016 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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>java-design-patterns</artifactId>
<groupId>com.iluwatar</groupId>
<version>1.20.0-SNAPSHOT</version>
</parent>
<artifactId>abstract-document</artifactId>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,72 @@
/**
* The MIT License
* Copyright (c) 2014-2016 Ilkka Seppälä
* <p>
* 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:
* <p>
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
* <p>
* 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.
*/
package com.iluwatar.abstractdocument;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Function;
import java.util.stream.Stream;
/**
* Abstract implementation of Document interface
*/
public abstract class AbstractDocument implements Document {
private final Map<String, Object> properties;
protected AbstractDocument(Map<String, Object> properties) {
Objects.requireNonNull(properties, "properties map is required");
this.properties = properties;
}
@Override
public Void put(String key, Object value) {
properties.put(key, value);
return null;
}
@Override
public Object get(String key) {
return properties.get(key);
}
@Override
public <T> Stream<T> children(String key, Function<Map<String, Object>, T> constructor) {
Optional<List<Map<String, Object>>> any = Stream.of(get(key)).filter(el -> el != null)
.map(el -> (List<Map<String, Object>>) el).findAny();
return any.isPresent() ? any.get().stream().map(constructor) : Stream.empty();
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append(getClass().getName()).append("[");
properties.entrySet()
.forEach(e -> builder.append("[").append(e.getKey()).append(" : ").append(e.getValue()).append("]"));
builder.append("]");
return builder.toString();
}
}

View File

@ -0,0 +1,91 @@
/**
* The MIT License
* Copyright (c) 2014-2016 Ilkka Seppälä
* <p>
* 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:
* <p>
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
* <p>
* 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.
*/
package com.iluwatar.abstractdocument;
import com.iluwatar.abstractdocument.domain.Car;
import com.iluwatar.abstractdocument.domain.HasModel;
import com.iluwatar.abstractdocument.domain.HasParts;
import com.iluwatar.abstractdocument.domain.HasPrice;
import com.iluwatar.abstractdocument.domain.HasType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* The Abstract Document pattern enables handling additional, non-static
* properties. This pattern uses concept of traits to enable type safety and
* separate properties of different classes into set of interfaces.
* <p>
* <p>
* In Abstract Document pattern,({@link AbstractDocument}) fully implements
* {@link Document}) interface. Traits are then defined to enable access to
* properties in usual, static way.
*/
public class App {
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
/**
* Executes the App
*/
public App() {
LOGGER.info("Constructing parts and car");
Map<String, Object> carProperties = new HashMap<>();
carProperties.put(HasModel.PROPERTY, "300SL");
carProperties.put(HasPrice.PROPERTY, 10000L);
Map<String, Object> wheelProperties = new HashMap<>();
wheelProperties.put(HasType.PROPERTY, "wheel");
wheelProperties.put(HasModel.PROPERTY, "15C");
wheelProperties.put(HasPrice.PROPERTY, 100L);
Map<String, Object> doorProperties = new HashMap<>();
doorProperties.put(HasType.PROPERTY, "door");
doorProperties.put(HasModel.PROPERTY, "Lambo");
doorProperties.put(HasPrice.PROPERTY, 300L);
carProperties.put(HasParts.PROPERTY, Arrays.asList(wheelProperties, doorProperties));
Car car = new Car(carProperties);
LOGGER.info("Here is our car:");
LOGGER.info("-> model: {}", car.getModel().get());
LOGGER.info("-> price: {}", car.getPrice().get());
LOGGER.info("-> parts: ");
car.getParts().forEach(p -> LOGGER.info("\t{}/{}/{}", p.getType().get(), p.getModel().get(), p.getPrice().get()));
}
/**
* Program entry point
*
* @param args command line args
*/
public static void main(String[] args) {
new App();
}
}

View File

@ -0,0 +1,59 @@
/**
* The MIT License
* Copyright (c) 2014-2016 Ilkka Seppälä
* <p>
* 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:
* <p>
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
* <p>
* 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.
*/
package com.iluwatar.abstractdocument;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Stream;
/**
* Document interface
*/
public interface Document {
/**
* Puts the value related to the key
*
* @param key element key
* @param value element value
* @return Void
*/
Void put(String key, Object value);
/**
* Gets the value for the key
*
* @param key element key
* @return value or null
*/
Object get(String key);
/**
* Gets the stream of child documents
*
* @param key element key
* @param constructor constructor of child class
* @return child documents
*/
<T> Stream<T> children(String key, Function<Map<String, Object>, T> constructor);
}

View File

@ -0,0 +1,38 @@
/**
* The MIT License
* Copyright (c) 2014-2016 Ilkka Seppälä
* <p>
* 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:
* <p>
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
* <p>
* 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.
*/
package com.iluwatar.abstractdocument.domain;
import java.util.Map;
import com.iluwatar.abstractdocument.AbstractDocument;
/**
* Car entity
*/
public class Car extends AbstractDocument implements HasModel, HasPrice, HasParts {
public Car(Map<String, Object> properties) {
super(properties);
}
}

View File

@ -0,0 +1,40 @@
/**
* The MIT License
* Copyright (c) 2014-2016 Ilkka Seppälä
* <p>
* 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:
* <p>
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
* <p>
* 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.
*/
package com.iluwatar.abstractdocument.domain;
import java.util.Optional;
import com.iluwatar.abstractdocument.Document;
/**
* HasModel trait for static access to 'model' property
*/
public interface HasModel extends Document {
String PROPERTY = "model";
default Optional<String> getModel() {
return Optional.ofNullable((String) get(PROPERTY));
}
}

View File

@ -0,0 +1,40 @@
/**
* The MIT License
* Copyright (c) 2014-2016 Ilkka Seppälä
* <p>
* 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:
* <p>
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
* <p>
* 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.
*/
package com.iluwatar.abstractdocument.domain;
import java.util.stream.Stream;
import com.iluwatar.abstractdocument.Document;
/**
* HasParts trait for static access to 'parts' property
*/
public interface HasParts extends Document {
String PROPERTY = "parts";
default Stream<Part> getParts() {
return children(PROPERTY, Part::new);
}
}

View File

@ -0,0 +1,40 @@
/**
* The MIT License
* Copyright (c) 2014-2016 Ilkka Seppälä
* <p>
* 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:
* <p>
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
* <p>
* 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.
*/
package com.iluwatar.abstractdocument.domain;
import java.util.Optional;
import com.iluwatar.abstractdocument.Document;
/**
* HasPrice trait for static access to 'price' property
*/
public interface HasPrice extends Document {
String PROPERTY = "price";
default Optional<Number> getPrice() {
return Optional.ofNullable((Number) get(PROPERTY));
}
}

View File

@ -0,0 +1,40 @@
/**
* The MIT License
* Copyright (c) 2014-2016 Ilkka Seppälä
* <p>
* 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:
* <p>
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
* <p>
* 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.
*/
package com.iluwatar.abstractdocument.domain;
import com.iluwatar.abstractdocument.Document;
import java.util.Optional;
/**
* HasType trait for static access to 'type' property
*/
public interface HasType extends Document {
String PROPERTY = "type";
default Optional<String> getType() {
return Optional.ofNullable((String) get(PROPERTY));
}
}

View File

@ -0,0 +1,38 @@
/**
* The MIT License
* Copyright (c) 2014-2016 Ilkka Seppälä
* <p>
* 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:
* <p>
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
* <p>
* 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.
*/
package com.iluwatar.abstractdocument.domain;
import java.util.Map;
import com.iluwatar.abstractdocument.AbstractDocument;
/**
* Part entity
*/
public class Part extends AbstractDocument implements HasType, HasModel, HasPrice {
public Part(Map<String, Object> properties) {
super(properties);
}
}

View File

@ -0,0 +1,88 @@
/**
* The MIT License
* Copyright (c) 2014-2016 Ilkka Seppälä
* <p>
* 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:
* <p>
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
* <p>
* 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.
*/
package com.iluwatar.abstractdocument;
import org.junit.jupiter.api.Test;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Stream;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
/**
* AbstractDocument test class
*/
public class AbstractDocumentTest {
private static final String KEY = "key";
private static final String VALUE = "value";
private class DocumentImplementation extends AbstractDocument {
DocumentImplementation(Map<String, Object> properties) {
super(properties);
}
}
private DocumentImplementation document = new DocumentImplementation(new HashMap<>());
@Test
public void shouldPutAndGetValue() {
document.put(KEY, VALUE);
assertEquals(VALUE, document.get(KEY));
}
@Test
public void shouldRetrieveChildren() {
Map<String, Object> child1 = new HashMap<>();
Map<String, Object> child2 = new HashMap<>();
List<Map<String, Object>> children = Arrays.asList(child1, child2);
document.put(KEY, children);
Stream<DocumentImplementation> childrenStream = document.children(KEY, DocumentImplementation::new);
assertNotNull(children);
assertEquals(2, childrenStream.count());
}
@Test
public void shouldRetrieveEmptyStreamForNonExistingChildren() {
Stream<DocumentImplementation> children = document.children(KEY, DocumentImplementation::new);
assertNotNull(children);
assertEquals(0, children.count());
}
@Test
public void shouldIncludePropsInToString() {
Map<String, Object> props = new HashMap<>();
props.put(KEY, VALUE);
DocumentImplementation document = new DocumentImplementation(props);
assertNotNull(document.toString().contains(KEY));
assertNotNull(document.toString().contains(VALUE));
}
}

View File

@ -0,0 +1,37 @@
/**
* The MIT License
* Copyright (c) 2014-2016 Ilkka Seppälä
* <p>
* 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:
* <p>
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
* <p>
* 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.
*/
package com.iluwatar.abstractdocument;
import org.junit.jupiter.api.Test;
/**
* Simple App test
*/
public class AppTest {
@Test
public void shouldExecuteAppWithoutException() {
App.main(null);
}
}

View File

@ -0,0 +1,77 @@
/**
* The MIT License
* Copyright (c) 2014-2016 Ilkka Seppälä
* <p>
* 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:
* <p>
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
* <p>
* 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.
*/
package com.iluwatar.abstractdocument;
import com.iluwatar.abstractdocument.domain.Car;
import com.iluwatar.abstractdocument.domain.HasModel;
import com.iluwatar.abstractdocument.domain.HasParts;
import com.iluwatar.abstractdocument.domain.HasPrice;
import com.iluwatar.abstractdocument.domain.HasType;
import com.iluwatar.abstractdocument.domain.Part;
import org.junit.jupiter.api.Test;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* Test for Part and Car
*/
public class DomainTest {
private static final String TEST_PART_TYPE = "test-part-type";
private static final String TEST_PART_MODEL = "test-part-model";
private static final long TEST_PART_PRICE = 0L;
private static final String TEST_CAR_MODEL = "test-car-model";
private static final long TEST_CAR_PRICE = 1L;
@Test
public void shouldConstructPart() {
Map<String, Object> partProperties = new HashMap<>();
partProperties.put(HasType.PROPERTY, TEST_PART_TYPE);
partProperties.put(HasModel.PROPERTY, TEST_PART_MODEL);
partProperties.put(HasPrice.PROPERTY, TEST_PART_PRICE);
Part part = new Part(partProperties);
assertEquals(TEST_PART_TYPE, part.getType().get());
assertEquals(TEST_PART_MODEL, part.getModel().get());
assertEquals(TEST_PART_PRICE, part.getPrice().get());
}
@Test
public void shouldConstructCar() {
Map<String, Object> carProperties = new HashMap<>();
carProperties.put(HasModel.PROPERTY, TEST_CAR_MODEL);
carProperties.put(HasPrice.PROPERTY, TEST_CAR_PRICE);
carProperties.put(HasParts.PROPERTY, Arrays.asList(new HashMap<>(), new HashMap<>()));
Car car = new Car(carProperties);
assertEquals(TEST_CAR_MODEL, car.getModel().get());
assertEquals(TEST_CAR_PRICE, car.getPrice().get());
assertEquals(2, car.getParts().count());
}
}

199
abstract-factory/README.md Normal file
View File

@ -0,0 +1,199 @@
---
layout: pattern
title: Abstract Factory
folder: abstract-factory
permalink: /patterns/abstract-factory/
categories: Creational
tags:
- Java
- Gang Of Four
- Difficulty-Intermediate
---
## Also known as
Kit
## Intent
Provide an interface for creating families of related or dependent
objects without specifying their concrete classes.
## Explanation
Real world example
> To create a kingdom we need objects with 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.
In plain words
> A factory of factories; a factory that groups the individual but related/dependent factories together without specifying their concrete classes.
Wikipedia says
> The abstract factory pattern provides a way to encapsulate a group of individual factories that have a common theme without specifying their concrete classes
**Programmatic Example**
Translating the kingdom example above. First of all we have some interfaces and implementation for the objects in the kingdom
```java
public interface Castle {
String getDescription();
}
public interface King {
String getDescription();
}
public interface Army {
String getDescription();
}
// Elven implementations ->
public class ElfCastle implements Castle {
static final String DESCRIPTION = "This is the Elven castle!";
@Override
public String getDescription() {
return DESCRIPTION;
}
}
public class ElfKing implements King {
static final String DESCRIPTION = "This is the Elven king!";
@Override
public String getDescription() {
return DESCRIPTION;
}
}
public class ElfArmy implements Army {
static final String DESCRIPTION = "This is the Elven Army!";
@Override
public String getDescription() {
return DESCRIPTION;
}
}
// Orcish implementations similarly...
```
Then we have the abstraction and implementations for the kingdom factory
```java
public interface KingdomFactory {
Castle createCastle();
King createKing();
Army createArmy();
}
public class ElfKingdomFactory implements KingdomFactory {
public Castle createCastle() {
return new ElfCastle();
}
public King createKing() {
return new ElfKing();
}
public Army createArmy() {
return new ElfArmy();
}
}
public class OrcKingdomFactory implements KingdomFactory {
public Castle createCastle() {
return new OrcCastle();
}
public King createKing() {
return new OrcKing();
}
public Army createArmy() {
return new OrcArmy();
}
}
```
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.
```java
KingdomFactory factory = new ElfKingdomFactory();
Castle castle = factory.createCastle();
King king = factory.createKing();
Army army = factory.createArmy();
castle.getDescription(); // Output: This is the Elven castle!
king.getDescription(); // Output: This is the Elven king!
army.getDescription(); // Output: This is the Elven Army!
```
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.
The client can use FactoryMaker to create the desired concrete factory which, in turn, will produce different concrete objects (Army, King, Castle).
In this example, we also used an enum to parameterize which type of kingdom factory the client will ask for.
```java
public static class FactoryMaker {
public enum KingdomType {
ELF, ORC
}
public static KingdomFactory makeFactory(KingdomType type) {
switch (type) {
case ELF:
return new ElfKingdomFactory();
case ORC:
return new OrcKingdomFactory();
default:
throw new IllegalArgumentException("KingdomType not supported.");
}
}
}
public static void main(String[] args) {
App app = new App();
LOGGER.info("Elf Kingdom");
app.createKingdom(FactoryMaker.makeFactory(KingdomType.ELF));
LOGGER.info(app.getArmy().getDescription());
LOGGER.info(app.getCastle().getDescription());
LOGGER.info(app.getKing().getDescription());
LOGGER.info("Orc Kingdom");
app.createKingdom(FactoryMaker.makeFactory(KingdomType.ORC));
-- similar use of the orc factory
}
```
## Applicability
Use the Abstract Factory pattern when
* a system should be independent of how its products are created, composed and represented
* a system should be configured with one of multiple families of products
* a family of related product objects is designed to be used together, and you need to enforce this constraint
* you want to provide a class library of products, and you want to reveal just their interfaces, not their implementations
* the lifetime of the dependency is conceptually shorter than the lifetime of the consumer.
* you need a run-time value to construct a particular dependency
* you want to decide which product to call from a family at runtime.
* you need to supply one or more parameters only known at run-time before you can resolve a dependency.
## Use Cases:
* Selecting to call the appropriate implementation of FileSystemAcmeService or DatabaseAcmeService or NetworkAcmeService at runtime.
* Unit test case writing becomes much easier
## Consequences:
* Dependency injection in java hides the service class dependencies that can lead to runtime errors that would have been caught at compile time.
## Tutorial
* [Abstract Factory Pattern Tutorial](https://www.journaldev.com/1418/abstract-factory-design-pattern-in-java)
## Presentations
* [Abstract Factory Pattern](etc/presentation.html)
## Real world examples
* [javax.xml.parsers.DocumentBuilderFactory](http://docs.oracle.com/javase/8/docs/api/javax/xml/parsers/DocumentBuilderFactory.html)
* [javax.xml.transform.TransformerFactory](http://docs.oracle.com/javase/8/docs/api/javax/xml/transform/TransformerFactory.html#newInstance--)
* [javax.xml.xpath.XPathFactory](http://docs.oracle.com/javase/8/docs/api/javax/xml/xpath/XPathFactory.html#newInstance--)
## Credits
* [Design Patterns: Elements of Reusable Object-Oriented Software](http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 21 KiB

View File

@ -1,159 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<class-diagram version="1.1.8" icons="true" automaticImage="PNG" always-add-relationships="false" generalizations="true"
realizations="true" associations="true" dependencies="false" nesting-relationships="true">
<interface id="1" language="java" name="com.iluwatar.abstractfactory.Army" project="abstract-factory"
file="/abstract-factory/src/main/java/com/iluwatar/abstractfactory/Army.java" binary="false" corner="BOTTOM_RIGHT">
<position height="70" width="161" x="1407" y="300"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/>
</display>
</interface>
<interface id="2" language="java" name="com.iluwatar.abstractfactory.KingdomFactory" project="abstract-factory"
file="/abstract-factory/src/main/java/com/iluwatar/abstractfactory/KingdomFactory.java" binary="false"
corner="BOTTOM_RIGHT">
<position height="124" width="161" x="1001" y="300"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/>
</display>
</interface>
<class id="3" language="java" name="com.iluwatar.abstractfactory.ElfCastle" project="abstract-factory"
file="/abstract-factory/src/main/java/com/iluwatar/abstractfactory/ElfCastle.java" binary="false"
corner="BOTTOM_RIGHT">
<position height="106" width="161" x="96" y="118"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/>
</display>
</class>
<class id="4" language="java" name="com.iluwatar.abstractfactory.ElfKingdomFactory" project="abstract-factory"
file="/abstract-factory/src/main/java/com/iluwatar/abstractfactory/ElfKingdomFactory.java" binary="false"
corner="BOTTOM_RIGHT">
<position height="142" width="161" x="900" y="118"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/>
</display>
</class>
<class id="5" language="java" name="com.iluwatar.abstractfactory.ElfKing" project="abstract-factory"
file="/abstract-factory/src/main/java/com/iluwatar/abstractfactory/ElfKing.java" binary="false"
corner="BOTTOM_RIGHT">
<position height="106" width="161" x="498" y="118"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/>
</display>
</class>
<interface id="6" language="java" name="com.iluwatar.abstractfactory.King" project="abstract-factory"
file="/abstract-factory/src/main/java/com/iluwatar/abstractfactory/King.java" binary="false" corner="BOTTOM_RIGHT">
<position height="70" width="161" x="599" y="300"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/>
</display>
</interface>
<class id="7" language="java" name="com.iluwatar.abstractfactory.OrcCastle" project="abstract-factory"
file="/abstract-factory/src/main/java/com/iluwatar/abstractfactory/OrcCastle.java" binary="false"
corner="BOTTOM_RIGHT">
<position height="106" width="161" x="297" y="118"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/>
</display>
</class>
<class id="8" language="java" name="com.iluwatar.abstractfactory.OrcKing" project="abstract-factory"
file="/abstract-factory/src/main/java/com/iluwatar/abstractfactory/OrcKing.java" binary="false"
corner="BOTTOM_RIGHT">
<position height="106" width="161" x="699" y="118"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/>
</display>
</class>
<class id="9" language="java" name="com.iluwatar.abstractfactory.ElfArmy" project="abstract-factory"
file="/abstract-factory/src/main/java/com/iluwatar/abstractfactory/ElfArmy.java" binary="false"
corner="BOTTOM_RIGHT">
<position height="106" width="161" x="1306" y="118"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/>
</display>
</class>
<class id="10" language="java" name="com.iluwatar.abstractfactory.OrcArmy" project="abstract-factory"
file="/abstract-factory/src/main/java/com/iluwatar/abstractfactory/OrcArmy.java" binary="false"
corner="BOTTOM_RIGHT">
<position height="106" width="161" x="1507" y="118"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/>
</display>
</class>
<interface id="11" language="java" name="com.iluwatar.abstractfactory.Castle" project="abstract-factory"
file="/abstract-factory/src/main/java/com/iluwatar/abstractfactory/Castle.java" binary="false" corner="BOTTOM_RIGHT">
<position height="70" width="161" x="197" y="300"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/>
</display>
</interface>
<class id="12" language="java" name="com.iluwatar.abstractfactory.OrcKingdomFactory" project="abstract-factory"
file="/abstract-factory/src/main/java/com/iluwatar/abstractfactory/OrcKingdomFactory.java" binary="false"
corner="BOTTOM_RIGHT">
<position height="142" width="165" x="1101" y="118"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/>
</display>
</class>
<realization id="13">
<end type="SOURCE" refId="4"/>
<end type="TARGET" refId="2"/>
</realization>
<realization id="14">
<end type="SOURCE" refId="7"/>
<end type="TARGET" refId="11"/>
</realization>
<realization id="15">
<end type="SOURCE" refId="8"/>
<end type="TARGET" refId="6"/>
</realization>
<realization id="16">
<end type="SOURCE" refId="3"/>
<end type="TARGET" refId="11"/>
</realization>
<realization id="17">
<end type="SOURCE" refId="10"/>
<end type="TARGET" refId="1"/>
</realization>
<realization id="18">
<end type="SOURCE" refId="12"/>
<end type="TARGET" refId="2"/>
</realization>
<realization id="19">
<end type="SOURCE" refId="5"/>
<end type="TARGET" refId="6"/>
</realization>
<realization id="20">
<end type="SOURCE" refId="9"/>
<end type="TARGET" refId="1"/>
</realization>
<classifier-display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/>
</classifier-display>
<association-display labels="true" multiplicity="true"/>
</class-diagram>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 57 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 57 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

View File

@ -0,0 +1,190 @@
<!--
The MIT License
Copyright (c) 2017 Rodolfo Forte
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.
-->
<!DOCTYPE html>
<html>
<head>
<title>Design Patterns - Abstract Factory Presentation</title>
<meta charset="utf-8">
<style>
@import url(https://fonts.googleapis.com/css?family=Yanone+Kaffeesatz);
@import url(https://fonts.googleapis.com/css?family=Droid+Serif:400,700,400italic);
@import url(https://fonts.googleapis.com/css?family=Ubuntu+Mono:400,700,400italic);
body { font-family: 'Droid Serif'; }
h1, h2, h3 {
font-family: 'Yanone Kaffeesatz';
font-weight: normal;
}
.remark-code, .remark-inline-code { font-family: 'Ubuntu Mono'; }
blockquote {
border-left: 0.3em solid rgba(0,0,0,0.5);
padding: 0 15px;
font-style: italic;
}
img {
max-width:100%;
}
</style>
</head>
<body>
<textarea id="source">
class: center, middle
# Abstract Factory
---
# Also known as
* Kit
---
# Intent
* Provide an interface for creating families of related or dependent objects without specifying their concrete classes
---
# Explanation
* [Wikipedia](https://en.wikipedia.org/wiki/Abstract_factory_pattern) says:
> "The abstract factory pattern provides a way to encapsulate a group of individual factories that have a common theme without specifying their concrete classes"
<br />
* In plain words:
* A factory that groups individual but related/dependent factories together without specifying their concrete classes;
* A factory of factories;
---
# Example
* In a factory that creates kingdoms, we need objects with common theme:
* Elven kingdom needs an Elven king, Elven castle and Elven army;
* Orcish kingdom needs an Orcish king, Orcish castle and Orcish army;
<br />
* There is a dependency between the objects in the kingdom;
---
# Diagram
* Based on the kingdom example, the diagram below showcases the different concrete factories and their concrete products:
.center[![Diagram](diagram1.png)]
---
# Diagram
* The class diagram below showcases the factory of factories;
* At runtime, we can define which Kingdom type is needed and pass it as a parameter to define which concrete KingdomFactory to instantiate;
* The concrete factory returned will then be able to produce the related objects of the specified type;
.center[![Diagram](diagram2.png)]
---
# Applicability
Use the Abstract Factory pattern when:
* A system should be independent of how its products are created, composed and represented;
* A system should be configured with one of multiple families of products;
* A family of related product objects is designed to be used together, and you need to enforce this constraint;
* You want to provide a class library of products, and you want to reveal just their interfaces, not their implementations;
---
# Applicability
Use the Abstract Factory pattern when:
* The lifetime of the dependency is conceptually shorter than the lifetime of the consumer;
* You need a run-time value to construct a particular dependency;
* You want to decide which product to call from a family at runtime;
* You need to supply one or more parameters only known at run-time before you can resolve a dependency;
---
#Use Cases
* Selecting to call the appropriate implementation of FileSystemAcmeService or DatabaseAcmeService or NetworkAcmeService at runtime;
* Unit test case writing becomes much easier;
---
# Consequences
* Dependency injection in java hides the service class dependencies that can lead to runtime errors that would have been caught at compile time
---
# Real world examples
[javax.xml.parsers.DocumentBuilderFactory](http://docs.oracle.com/javase/8/docs/api/javax/xml/parsers/DocumentBuilderFactory.html)
[javax.xml.transform.TransformerFactory](http://docs.oracle.com/javase/8/docs/api/javax/xml/transform/TransformerFactory.html#newInstance--)
[javax.xml.xpath.XPathFactory](http://docs.oracle.com/javase/8/docs/api/javax/xml/xpath/XPathFactory.html#newInstance--)
---
# Credits
* [Design Patterns: Elements of Reusable Object-Oriented Software](http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612)
---
# Tutorials
* Source code http://java-design-patterns.com/patterns/abstract-factory/
</textarea>
<script src="https://gnab.github.io/remark/downloads/remark-latest.min.js">
</script>
<script>
var slideshow = remark.create();
</script>
</body>
</html>

View File

@ -1,24 +0,0 @@
---
layout: pattern
title: Abstract Factory
folder: abstract-factory
permalink: /patterns/abstract-factory/
categories: Creational
tags: Java
---
**Intent:** Provide an interface for creating families of related or dependent
objects without specifying their concrete classes.
![alt text](./etc/abstract-factory_1.png "Abstract Factory")
**Applicability:** Use the Abstract Factory pattern when
* a system should be independent of how its products are created, composed and represented
* a system should be configured with one of multiple families of products
* a family of related product objects is designed to be used together, and you need to enforce this constraint
* you want to provide a class library of products, and you want to reveal just their interfaces, not their implementations
**Real world examples:**
* [javax.xml.parsers.DocumentBuilderFactory](http://docs.oracle.com/javase/8/docs/api/javax/xml/parsers/DocumentBuilderFactory.html)

View File

@ -1,17 +1,46 @@
<?xml version="1.0"?>
<!--
The MIT License
Copyright (c) 2014-2016 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.
-->
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.6.0</version>
<version>1.20.0-SNAPSHOT</version>
</parent>
<artifactId>abstract-factory</artifactId>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

View File

@ -1,73 +1,147 @@
/**
* The MIT License
* Copyright (c) 2014-2016 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.
*/
package com.iluwatar.abstractfactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.iluwatar.abstractfactory.App.FactoryMaker.KingdomType;
/**
*
* The essence of the Abstract Factory pattern is a factory interface
* ({@link KingdomFactory}) and its implementations ({@link ElfKingdomFactory},
* {@link OrcKingdomFactory}).
* The Abstract Factory pattern provides a way to encapsulate a group of individual factories that have a common theme
* without specifying their concrete classes. In normal usage, the client software creates a concrete implementation of
* the abstract factory and then uses the generic interface of the factory to create the concrete objects that are part
* of the theme. The client does not know (or care) which concrete objects it gets from each of these internal
* factories, since it uses only the generic interfaces of their products. This pattern separates the details of
* implementation of a set of objects from their general usage and relies on object composition, as object creation is
* implemented in methods exposed in the factory interface.
* <p>
* The example uses both concrete implementations to create a king, a castle and
* an army.
* The essence of the Abstract Factory pattern is a factory interface ({@link KingdomFactory}) and its implementations (
* {@link ElfKingdomFactory}, {@link OrcKingdomFactory}). The example uses both concrete implementations to create a
* king, a castle and an army.
*
*/
public class App {
private King king;
private Castle castle;
private Army army;
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
/**
* Creates kingdom
* @param factory
*/
public void createKingdom(final KingdomFactory factory) {
setKing(factory.createKing());
setCastle(factory.createCastle());
setArmy(factory.createArmy());
}
ElfKingdomFactory getElfKingdomFactory() {
return new ElfKingdomFactory();
}
OrcKingdomFactory getOrcKingdomFactory() {
return new OrcKingdomFactory();
}
King getKing(final KingdomFactory factory) {
return factory.createKing();
}
Castle getCastle(final KingdomFactory factory) {
return factory.createCastle();
}
Army getArmy(final KingdomFactory factory) {
return factory.createArmy();
}
public King getKing() {
return king;
}
private void setKing(final King king) {
this.king = king;
}
public Castle getCastle() {
return castle;
}
private void setCastle(final Castle castle) {
this.castle = castle;
}
public Army getArmy() {
return army;
}
private void setArmy(final Army army) {
this.army = army;
}
}
private King king;
private Castle castle;
private Army army;
/**
* Creates kingdom
*/
public void createKingdom(final KingdomFactory factory) {
setKing(factory.createKing());
setCastle(factory.createCastle());
setArmy(factory.createArmy());
}
King getKing(final KingdomFactory factory) {
return factory.createKing();
}
public King getKing() {
return king;
}
private void setKing(final King king) {
this.king = king;
}
Castle getCastle(final KingdomFactory factory) {
return factory.createCastle();
}
public Castle getCastle() {
return castle;
}
private void setCastle(final Castle castle) {
this.castle = castle;
}
Army getArmy(final KingdomFactory factory) {
return factory.createArmy();
}
public Army getArmy() {
return army;
}
private void setArmy(final Army army) {
this.army = army;
}
/**
* The factory of kingdom factories.
*/
public static class FactoryMaker {
/**
* Enumeration for the different types of Kingdoms.
*/
public enum KingdomType {
ELF, ORC
}
/**
* The factory method to create KingdomFactory concrete objects.
*/
public static KingdomFactory makeFactory(KingdomType type) {
switch (type) {
case ELF:
return new ElfKingdomFactory();
case ORC:
return new OrcKingdomFactory();
default:
throw new IllegalArgumentException("KingdomType not supported.");
}
}
}
/**
* Program entry point.
*
* @param args
* command line args
*/
public static void main(String[] args) {
App app = new App();
LOGGER.info("Elf Kingdom");
app.createKingdom(FactoryMaker.makeFactory(KingdomType.ELF));
LOGGER.info(app.getArmy().getDescription());
LOGGER.info(app.getCastle().getDescription());
LOGGER.info(app.getKing().getDescription());
LOGGER.info("Orc Kingdom");
app.createKingdom(FactoryMaker.makeFactory(KingdomType.ORC));
LOGGER.info(app.getArmy().getDescription());
LOGGER.info(app.getCastle().getDescription());
LOGGER.info(app.getKing().getDescription());
}
}

View File

@ -1,3 +1,25 @@
/**
* The MIT License
* Copyright (c) 2014-2016 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.
*/
package com.iluwatar.abstractfactory;
/**
@ -7,5 +29,5 @@ package com.iluwatar.abstractfactory;
*/
public interface Army {
String getDescription();
String getDescription();
}

View File

@ -1,3 +1,25 @@
/**
* The MIT License
* Copyright (c) 2014-2016 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.
*/
package com.iluwatar.abstractfactory;
/**
@ -7,5 +29,5 @@ package com.iluwatar.abstractfactory;
*/
public interface Castle {
String getDescription();
String getDescription();
}

View File

@ -1,3 +1,25 @@
/**
* The MIT License
* Copyright (c) 2014-2016 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.
*/
package com.iluwatar.abstractfactory;
/**
@ -7,10 +29,10 @@ package com.iluwatar.abstractfactory;
*/
public class ElfArmy implements Army {
static final String DESCRIPTION = "This is the Elven Army!";
static final String DESCRIPTION = "This is the Elven Army!";
@Override
public String getDescription() {
return DESCRIPTION;
}
@Override
public String getDescription() {
return DESCRIPTION;
}
}

View File

@ -1,3 +1,25 @@
/**
* The MIT License
* Copyright (c) 2014-2016 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.
*/
package com.iluwatar.abstractfactory;
/**
@ -7,10 +29,10 @@ package com.iluwatar.abstractfactory;
*/
public class ElfCastle implements Castle {
static final String DESCRIPTION = "This is the Elven castle!";
static final String DESCRIPTION = "This is the Elven castle!";
@Override
public String getDescription() {
return DESCRIPTION;
}
@Override
public String getDescription() {
return DESCRIPTION;
}
}

View File

@ -1,3 +1,25 @@
/**
* The MIT License
* Copyright (c) 2014-2016 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.
*/
package com.iluwatar.abstractfactory;
/**
@ -7,10 +29,10 @@ package com.iluwatar.abstractfactory;
*/
public class ElfKing implements King {
static final String DESCRIPTION = "This is the Elven king!";
@Override
public String getDescription() {
return DESCRIPTION;
}
static final String DESCRIPTION = "This is the Elven king!";
@Override
public String getDescription() {
return DESCRIPTION;
}
}

View File

@ -1,3 +1,25 @@
/**
* The MIT License
* Copyright (c) 2014-2016 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.
*/
package com.iluwatar.abstractfactory;
/**
@ -7,16 +29,16 @@ package com.iluwatar.abstractfactory;
*/
public class ElfKingdomFactory implements KingdomFactory {
public Castle createCastle() {
return new ElfCastle();
}
public Castle createCastle() {
return new ElfCastle();
}
public King createKing() {
return new ElfKing();
}
public King createKing() {
return new ElfKing();
}
public Army createArmy() {
return new ElfArmy();
}
public Army createArmy() {
return new ElfArmy();
}
}

View File

@ -1,3 +1,25 @@
/**
* The MIT License
* Copyright (c) 2014-2016 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.
*/
package com.iluwatar.abstractfactory;
/**
@ -7,5 +29,5 @@ package com.iluwatar.abstractfactory;
*/
public interface King {
String getDescription();
String getDescription();
}

View File

@ -1,3 +1,25 @@
/**
* The MIT License
* Copyright (c) 2014-2016 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.
*/
package com.iluwatar.abstractfactory;
/**
@ -7,10 +29,10 @@ package com.iluwatar.abstractfactory;
*/
public interface KingdomFactory {
Castle createCastle();
Castle createCastle();
King createKing();
King createKing();
Army createArmy();
Army createArmy();
}

View File

@ -1,3 +1,25 @@
/**
* The MIT License
* Copyright (c) 2014-2016 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.
*/
package com.iluwatar.abstractfactory;
/**
@ -7,10 +29,10 @@ package com.iluwatar.abstractfactory;
*/
public class OrcArmy implements Army {
static final String DESCRIPTION = "This is the Orc Army!";
static final String DESCRIPTION = "This is the Orc Army!";
@Override
public String getDescription() {
return DESCRIPTION;
}
@Override
public String getDescription() {
return DESCRIPTION;
}
}

View File

@ -1,3 +1,25 @@
/**
* The MIT License
* Copyright (c) 2014-2016 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.
*/
package com.iluwatar.abstractfactory;
/**
@ -7,10 +29,10 @@ package com.iluwatar.abstractfactory;
*/
public class OrcCastle implements Castle {
static final String DESCRIPTION = "This is the Orc castle!";
static final String DESCRIPTION = "This is the Orc castle!";
@Override
public String getDescription() {
return DESCRIPTION;
}
@Override
public String getDescription() {
return DESCRIPTION;
}
}

View File

@ -1,3 +1,25 @@
/**
* The MIT License
* Copyright (c) 2014-2016 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.
*/
package com.iluwatar.abstractfactory;
/**
@ -7,10 +29,10 @@ package com.iluwatar.abstractfactory;
*/
public class OrcKing implements King {
static final String DESCRIPTION = "This is the Orc king!";
@Override
public String getDescription() {
return DESCRIPTION;
}
static final String DESCRIPTION = "This is the Orc king!";
@Override
public String getDescription() {
return DESCRIPTION;
}
}

View File

@ -1,3 +1,25 @@
/**
* The MIT License
* Copyright (c) 2014-2016 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.
*/
package com.iluwatar.abstractfactory;
/**
@ -7,16 +29,15 @@ package com.iluwatar.abstractfactory;
*/
public class OrcKingdomFactory implements KingdomFactory {
public Castle createCastle() {
return new OrcCastle();
}
public Castle createCastle() {
return new OrcCastle();
}
public King createKing() {
return new OrcKing();
}
public Army createArmy() {
return new OrcArmy();
}
public King createKing() {
return new OrcKing();
}
public Army createArmy() {
return new OrcArmy();
}
}

View File

@ -0,0 +1,106 @@
/**
* The MIT License
* Copyright (c) 2014-2016 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.
*/
package com.iluwatar.abstractfactory;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import com.iluwatar.abstractfactory.App.FactoryMaker;
import com.iluwatar.abstractfactory.App.FactoryMaker.KingdomType;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
/**
* Test for abstract factory
*/
public class AbstractFactoryTest {
private App app = new App();
private KingdomFactory elfFactory;
private KingdomFactory orcFactory;
@BeforeEach
public void setUp() {
elfFactory = FactoryMaker.makeFactory(KingdomType.ELF);
orcFactory = FactoryMaker.makeFactory(KingdomType.ORC);
}
@Test
public void king() {
final King elfKing = app.getKing(elfFactory);
assertTrue(elfKing instanceof ElfKing);
assertEquals(ElfKing.DESCRIPTION, elfKing.getDescription());
final King orcKing = app.getKing(orcFactory);
assertTrue(orcKing instanceof OrcKing);
assertEquals(OrcKing.DESCRIPTION, orcKing.getDescription());
}
@Test
public void castle() {
final Castle elfCastle = app.getCastle(elfFactory);
assertTrue(elfCastle instanceof ElfCastle);
assertEquals(ElfCastle.DESCRIPTION, elfCastle.getDescription());
final Castle orcCastle = app.getCastle(orcFactory);
assertTrue(orcCastle instanceof OrcCastle);
assertEquals(OrcCastle.DESCRIPTION, orcCastle.getDescription());
}
@Test
public void army() {
final Army elfArmy = app.getArmy(elfFactory);
assertTrue(elfArmy instanceof ElfArmy);
assertEquals(ElfArmy.DESCRIPTION, elfArmy.getDescription());
final Army orcArmy = app.getArmy(orcFactory);
assertTrue(orcArmy instanceof OrcArmy);
assertEquals(OrcArmy.DESCRIPTION, orcArmy.getDescription());
}
@Test
public void createElfKingdom() {
app.createKingdom(elfFactory);
final King king = app.getKing();
final Castle castle = app.getCastle();
final Army army = app.getArmy();
assertTrue(king instanceof ElfKing);
assertEquals(ElfKing.DESCRIPTION, king.getDescription());
assertTrue(castle instanceof ElfCastle);
assertEquals(ElfCastle.DESCRIPTION, castle.getDescription());
assertTrue(army instanceof ElfArmy);
assertEquals(ElfArmy.DESCRIPTION, army.getDescription());
}
@Test
public void createOrcKingdom() {
app.createKingdom(orcFactory);
final King king = app.getKing();
final Castle castle = app.getCastle();
final Army army = app.getArmy();
assertTrue(king instanceof OrcKing);
assertEquals(OrcKing.DESCRIPTION, king.getDescription());
assertTrue(castle instanceof OrcCastle);
assertEquals(OrcCastle.DESCRIPTION, castle.getDescription());
assertTrue(army instanceof OrcArmy);
assertEquals(OrcArmy.DESCRIPTION, army.getDescription());
}
}

View File

@ -1,77 +1,38 @@
/**
* The MIT License
* Copyright (c) 2014-2016 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.
*/
package com.iluwatar.abstractfactory;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.io.IOException;
/**
* Tests that Abstract Factory example runs without errors.
*/
public class AppTest {
private App app = new App();;
private KingdomFactory elfFactory;
private KingdomFactory orcFactory;
@Before
public void setUp() {
elfFactory = app.getElfKingdomFactory();
orcFactory = app.getOrcKingdomFactory();
}
@Test
public void king() {
final King elfKing = app.getKing(elfFactory);
assertTrue(elfKing instanceof ElfKing);
assertEquals(ElfKing.DESCRIPTION, elfKing.getDescription());
final King orcKing = app.getKing(orcFactory);
assertTrue(orcKing instanceof OrcKing);
assertEquals(OrcKing.DESCRIPTION, orcKing.getDescription());
}
@Test
public void castle() {
final Castle elfCastle = app.getCastle(elfFactory);
assertTrue(elfCastle instanceof ElfCastle);
assertEquals(ElfCastle.DESCRIPTION, elfCastle.getDescription());
final Castle orcCastle = app.getCastle(orcFactory);
assertTrue(orcCastle instanceof OrcCastle);
assertEquals(OrcCastle.DESCRIPTION, orcCastle.getDescription());
}
@Test
public void army() {
final Army elfArmy = app.getArmy(elfFactory);
assertTrue(elfArmy instanceof ElfArmy);
assertEquals(ElfArmy.DESCRIPTION, elfArmy.getDescription());
final Army orcArmy = app.getArmy(orcFactory);
assertTrue(orcArmy instanceof OrcArmy);
assertEquals(OrcArmy.DESCRIPTION, orcArmy.getDescription());
}
@Test
public void createElfKingdom() {
app.createKingdom(elfFactory);
final King king = app.getKing();
final Castle castle = app.getCastle();
final Army army = app.getArmy();
assertTrue(king instanceof ElfKing);
assertEquals(ElfKing.DESCRIPTION, king.getDescription());
assertTrue(castle instanceof ElfCastle);
assertEquals(ElfCastle.DESCRIPTION, castle.getDescription());
assertTrue(army instanceof ElfArmy);
assertEquals(ElfArmy.DESCRIPTION, army.getDescription());
}
@Test
public void createOrcKingdom() {
app.createKingdom(orcFactory);
final King king = app.getKing();
final Castle castle = app.getCastle();
final Army army = app.getArmy();
assertTrue(king instanceof OrcKing);
assertEquals(OrcKing.DESCRIPTION, king.getDescription());
assertTrue(castle instanceof OrcCastle);
assertEquals(OrcCastle.DESCRIPTION, castle.getDescription());
assertTrue(army instanceof OrcArmy);
assertEquals(OrcArmy.DESCRIPTION, army.getDescription());
}
@Test
public void test() throws IOException {
String[] args = {};
App.main(args);
}
}

39
acyclic-visitor/README.md Normal file
View File

@ -0,0 +1,39 @@
---
layout: pattern
title: Acyclic Visitor
folder: acyclic-visitor
permalink: /patterns/acyclic-visitor/
categories: Behavioral
tags:
- Java
- Difficulty-Intermediate
---
![alt text](./etc/acyclic-visitor.png "Acyclic Visitor")
## Intent
Allow new functions to be added to existing class hierarchies without affecting those hierarchies, and without creating the troublesome dependency cycles that are inherent to the GOF VISITOR Pattern.
## Applicability
This pattern can be used:
* When you need to add a new function to an existing hierarchy without the need to alter or affect that hierarchy.
* When there are functions that operate upon a hierarchy, but which do not belong in the hierarchy itself. e.g. the ConfigureForDOS / ConfigureForUnix / ConfigureForX issue.
* When you need to perform very different operations on an object depending upon its type.
* When the visited class hierarchy will be frequently extended with new derivatives of the Element class.
* When the recompilation, relinking, retesting or redistribution of the derivatives of Element is very expensive.
## Consequences
The good:
* No dependency cycles between class hierarchies.
* No need to recompile all the visitors if a new one is added.
* Does not cause compilation failure in existing visitors if class hierarchy has a new member.
The bad:
* Violates the principle of least surprise or Liskov's Substitution principle by showing that it can accept all visitors but actually only being interested in particular visitors.
* Parallel hierarchy of visitors has to be created for all members in visitable class hierarchy.
## Related patterns
* [Visitor Pattern](../visitor/README.md)
## Credits
* [Acyclic Visitor](http://condor.depaul.edu/dmumaugh/OOT/Design-Principles/acv.pdf)

View File

@ -1,113 +1,111 @@
<?xml version="1.0" encoding="UTF-8"?>
<class-diagram version="1.1.8" icons="true" automaticImage="PNG" always-add-relationships="false" generalizations="true"
realizations="true" associations="true" dependencies="false" nesting-relationships="true">
<class id="1" language="java" name="com.iluwatar.factory.method.OrcBlacksmith" project="factory-method"
file="/factory-method/src/main/java/com/iluwatar/factory/method/OrcBlacksmith.java" binary="false"
<class-diagram version="1.2.2" icons="true" always-add-relationships="false" generalizations="true" realizations="true"
associations="true" dependencies="false" nesting-relationships="true" router="FAN">
<interface id="1" language="java" name="com.iluwatar.acyclicvisitor.ModemVisitor" project="acyclic-visitor"
file="/acyclic-visitor/src/main/java/com/iluwatar/acyclicvisitor/ModemVisitor.java" binary="false"
corner="BOTTOM_RIGHT">
<position height="106" width="280" x="-46" y="239"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/>
</display>
</class>
<interface id="2" language="java" name="com.iluwatar.factory.method.Blacksmith" project="factory-method"
file="/factory-method/src/main/java/com/iluwatar/factory/method/Blacksmith.java" binary="false"
corner="BOTTOM_RIGHT">
<position height="88" width="280" x="114" y="385"/>
<position height="-1" width="-1" x="860" y="67"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/>
</display>
</interface>
<enumeration id="3" language="java" name="com.iluwatar.factory.method.WeaponType" project="factory-method"
file="/factory-method/src/main/java/com/iluwatar/factory/method/WeaponType.java" binary="false"
<class id="2" language="java" name="com.iluwatar.acyclicvisitor.Modem" project="acyclic-visitor"
file="/acyclic-visitor/src/main/java/com/iluwatar/acyclicvisitor/Modem.java" binary="false" corner="BOTTOM_RIGHT">
<position height="-1" width="-1" x="327" y="77"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/>
</display>
</class>
<class id="3" language="java" name="com.iluwatar.acyclicvisitor.ConfigureForUnixVisitor" project="acyclic-visitor"
file="/acyclic-visitor/src/main/java/com/iluwatar/acyclicvisitor/ConfigureForUnixVisitor.java" binary="false"
corner="BOTTOM_RIGHT">
<position height="196" width="210" x="793" y="385"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/>
</display>
</enumeration>
<class id="4" language="java" name="com.iluwatar.factory.method.OrcWeapon" project="factory-method"
file="/factory-method/src/main/java/com/iluwatar/factory/method/OrcWeapon.java" binary="false" corner="BOTTOM_RIGHT">
<position height="106" width="178" x="806" y="239"/>
<position height="124" width="196" x="647" y="225"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/>
</display>
</class>
<class id="5" language="java" name="com.iluwatar.factory.method.ElfWeapon" project="factory-method"
file="/factory-method/src/main/java/com/iluwatar/factory/method/ElfWeapon.java" binary="false" corner="BOTTOM_RIGHT">
<position height="106" width="172" x="594" y="239"/>
<class id="4" language="java" name="com.iluwatar.acyclicvisitor.Zoom" project="acyclic-visitor"
file="/acyclic-visitor/src/main/java/com/iluwatar/acyclicvisitor/Zoom.java" binary="false" corner="BOTTOM_RIGHT">
<position height="-1" width="-1" x="203" y="305"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/>
</display>
</class>
<interface id="6" language="java" name="com.iluwatar.factory.method.Weapon" project="factory-method"
file="/factory-method/src/main/java/com/iluwatar/factory/method/Weapon.java" binary="false" corner="BOTTOM_RIGHT">
<position height="70" width="159" x="594" y="385"/>
<interface id="5" language="java" name="com.iluwatar.acyclicvisitor.HayesVisitor" project="acyclic-visitor"
file="/acyclic-visitor/src/main/java/com/iluwatar/acyclicvisitor/HayesVisitor.java" binary="false"
corner="BOTTOM_RIGHT">
<position height="-1" width="-1" x="1019" y="468"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/>
</display>
</interface>
<class id="7" language="java" name="com.iluwatar.factory.method.ElfBlacksmith" project="factory-method"
file="/factory-method/src/main/java/com/iluwatar/factory/method/ElfBlacksmith.java" binary="false"
<interface id="6" language="java" name="com.iluwatar.acyclicvisitor.ZoomVisitor" project="acyclic-visitor"
file="/acyclic-visitor/src/main/java/com/iluwatar/acyclicvisitor/ZoomVisitor.java" binary="false"
corner="BOTTOM_RIGHT">
<position height="106" width="280" x="274" y="239"/>
<position height="-1" width="-1" x="758" y="467"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/>
</display>
</interface>
<class id="7" language="java" name="com.iluwatar.acyclicvisitor.Hayes" project="acyclic-visitor"
file="/acyclic-visitor/src/main/java/com/iluwatar/acyclicvisitor/Hayes.java" binary="false" corner="BOTTOM_RIGHT">
<position height="-1" width="-1" x="479" y="307"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/>
</display>
</class>
<realization id="8">
<end type="SOURCE" refId="4"/>
<end type="TARGET" refId="6"/>
</realization>
<realization id="9">
<class id="8" language="java" name="com.iluwatar.acyclicvisitor.ConfigureForDosVisitor" project="acyclic-visitor"
file="/acyclic-visitor/src/main/java/com/iluwatar/acyclicvisitor/ConfigureForDosVisitor.java" binary="false"
corner="BOTTOM_RIGHT">
<position height="142" width="192" x="883" y="225"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/>
</display>
</class>
<generalization id="9">
<end type="SOURCE" refId="7"/>
<end type="TARGET" refId="2"/>
</realization>
</generalization>
<realization id="10">
<end type="SOURCE" refId="5"/>
<end type="SOURCE" refId="8"/>
<end type="TARGET" refId="6"/>
</realization>
<association id="11">
<end type="SOURCE" refId="4" navigable="false">
<attribute id="12" name="weaponType">
<position height="0" width="0" x="0" y="0"/>
</attribute>
<multiplicity id="13" minimum="0" maximum="1">
<position height="0" width="0" x="0" y="0"/>
</multiplicity>
</end>
<end type="TARGET" refId="3" navigable="true"/>
<display labels="true" multiplicity="true"/>
</association>
<realization id="14">
<end type="SOURCE" refId="1"/>
<end type="TARGET" refId="2"/>
<realization id="11">
<end type="SOURCE" refId="8"/>
<end type="TARGET" refId="5"/>
</realization>
<association id="15">
<end type="SOURCE" refId="5" navigable="false">
<attribute id="16" name="weaponType">
<position height="0" width="0" x="0" y="0"/>
</attribute>
<multiplicity id="17" minimum="0" maximum="1">
<position height="0" width="0" x="0" y="0"/>
</multiplicity>
</end>
<end type="TARGET" refId="3" navigable="true"/>
<display labels="true" multiplicity="true"/>
</association>
<realization id="12">
<end type="SOURCE" refId="3"/>
<end type="TARGET" refId="6"/>
</realization>
<realization id="13">
<end type="SOURCE" refId="3"/>
<end type="TARGET" refId="1"/>
</realization>
<realization id="14">
<end type="SOURCE" refId="8"/>
<end type="TARGET" refId="1"/>
</realization>
<generalization id="15">
<end type="SOURCE" refId="4"/>
<end type="TARGET" refId="2"/>
</generalization>
<classifier-display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

76
acyclic-visitor/pom.xml Normal file
View File

@ -0,0 +1,76 @@
<!--
The MIT License
Copyright (c) 2014 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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.20.0-SNAPSHOT</version>
</parent>
<artifactId>acyclic-visitor</artifactId>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.assertj/assertj-core -->
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.9.1</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/uk.org.lidalia/slf4j-test -->
<dependency>
<groupId>uk.org.lidalia</groupId>
<artifactId>slf4j-test</artifactId>
<version>1.0.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.9.5</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,31 @@
/**
* The MIT License
* Copyright (c) 2014-2016 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.
*/
package com.iluwatar.acyclicvisitor;
/**
* All ModemVisitor interface extends all visitor interfaces. This interface
* provides ease of use when a visitor needs to visit all modem types.
*/
public interface AllModemVisitor extends ZoomVisitor, HayesVisitor{
}

View File

@ -0,0 +1,55 @@
/**
* The MIT License
* Copyright (c) 2014-2016 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.
*/
package com.iluwatar.acyclicvisitor;
/**
* The Acyclic Visitor pattern allows new functions to be added to existing class
* hierarchies without affecting those hierarchies, and without creating the dependency
* cycles that are inherent to the GoF Visitor pattern, by making the Visitor base class
* degenerate
* <p>
* In this example the visitor base class is {@link ModemVisitor}. The base class of the
* visited hierarchy is {@link Modem} and has two children {@link Hayes} and {@link Zoom}
* each one having its own visitor interface {@link HayesVisitor} and {@link ZoomVisitor}
* respectively. {@link ConfigureForUnixVisitor} and {@link ConfigureForDosVisitor}
* implement each derivative's visit method only if it is required
*/
public class App {
/**
* Program's entry point
*/
public static void main(String[] args) {
ConfigureForUnixVisitor conUnix = new ConfigureForUnixVisitor();
ConfigureForDosVisitor conDos = new ConfigureForDosVisitor();
Zoom zoom = new Zoom();
Hayes hayes = new Hayes();
hayes.accept(conDos); // Hayes modem with Unix configurator
zoom.accept(conDos); // Zoom modem with Dos configurator
hayes.accept(conUnix); // Hayes modem with Unix configurator
zoom.accept(conUnix); // Zoom modem with Unix configurator
}
}

View File

@ -0,0 +1,43 @@
/**
* The MIT License
* Copyright (c) 2014-2016 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.
*/
package com.iluwatar.acyclicvisitor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* ConfigureForDosVisitor class implements both zoom's and hayes' visit method
* for Dos manufacturer
*/
public class ConfigureForDosVisitor implements AllModemVisitor {
private static final Logger LOGGER = LoggerFactory.getLogger(ConfigureForDosVisitor.class);
public void visit(Hayes hayes) {
LOGGER.info(hayes + " used with Dos configurator.");
}
public void visit(Zoom zoom) {
LOGGER.info(zoom + " used with Dos configurator.");
}
}

View File

@ -0,0 +1,40 @@
/**
* The MIT License
* Copyright (c) 2014-2016 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.
*/
package com.iluwatar.acyclicvisitor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* ConfigureForUnixVisitor class implements zoom's visit method for Unix
* manufacturer, unlike traditional visitor pattern, this class may selectively implement
* visit for other modems.
*/
public class ConfigureForUnixVisitor implements ZoomVisitor {
private static final Logger LOGGER = LoggerFactory.getLogger(ConfigureForUnixVisitor.class);
public void visit(Zoom zoom) {
LOGGER.info(zoom + " used with Unix configurator.");
}
}

View File

@ -0,0 +1,56 @@
/**
* The MIT License
* Copyright (c) 2014-2016 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.
*/
package com.iluwatar.acyclicvisitor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Hayes class implements its accept method
*/
public class Hayes extends Modem {
private static final Logger LOGGER = LoggerFactory.getLogger(ConfigureForDosVisitor.class);
/**
* Accepts all visitors but honors only HayesVisitor
*/
@Override
public void accept(ModemVisitor modemVisitor) {
if (modemVisitor instanceof HayesVisitor) {
((HayesVisitor) modemVisitor).visit(this);
} else {
LOGGER.info("Only HayesVisitor is allowed to visit Hayes modem");
}
}
/**
* Hayes' modem's toString
* method
*/
@Override
public String toString() {
return "Hayes modem";
}
}

View File

@ -0,0 +1,30 @@
/**
* The MIT License
* Copyright (c) 2014-2016 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.
*/
package com.iluwatar.acyclicvisitor;
/**
* HayesVisitor interface
*/
public interface HayesVisitor extends ModemVisitor {
void visit(Hayes hayes);
}

View File

@ -0,0 +1,30 @@
/**
* The MIT License
* Copyright (c) 2014-2016 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.
*/
package com.iluwatar.acyclicvisitor;
/**
* Modem abstract class
*/
public abstract class Modem {
public abstract void accept(ModemVisitor modemVisitor);
}

View File

@ -0,0 +1,32 @@
/**
* The MIT License
* Copyright (c) 2014-2016 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.
*/
package com.iluwatar.acyclicvisitor;
/**
* ModemVisitor interface does not contain any visit methods so that it does not
* depend on the visited hierarchy. Each derivative's visit method is declared in
* its own visitor interface
*/
public interface ModemVisitor {
// Visitor is a degenerate base class for all visitors.
}

View File

@ -0,0 +1,55 @@
/**
* The MIT License
* Copyright (c) 2014-2016 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.
*/
package com.iluwatar.acyclicvisitor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Zoom class implements its accept method
*/
public class Zoom extends Modem {
private static final Logger LOGGER = LoggerFactory.getLogger(ConfigureForDosVisitor.class);
/**
* Accepts all visitors but honors only ZoomVisitor
*/
@Override
public void accept(ModemVisitor modemVisitor) {
if (modemVisitor instanceof ZoomVisitor) {
((ZoomVisitor) modemVisitor).visit(this);
} else {
LOGGER.info("Only ZoomVisitor is allowed to visit Zoom modem");
}
}
/**
* Zoom modem's toString
* method
*/
@Override
public String toString() {
return "Zoom modem";
}
}

View File

@ -0,0 +1,30 @@
/**
* The MIT License
* Copyright (c) 2014-2016 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.
*/
package com.iluwatar.acyclicvisitor;
/**
* ZoomVisitor interface
*/
public interface ZoomVisitor extends ModemVisitor {
void visit(Zoom zoom);
}

View File

@ -0,0 +1,39 @@
/**
* The MIT License
* Copyright (c) 2014-2016 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.
*/
package com.iluwatar.acyclicvisitor;
import org.junit.jupiter.api.Test;
import com.iluwatar.acyclicvisitor.App;
/**
* Tests that the Acyclic Visitor example runs without errors.
*/
public class AppTest {
@Test
public void test() {
String[] args = {};
App.main(args);
}
}

View File

@ -0,0 +1,75 @@
/**
* The MIT License
* Copyright (c) 2014-2016 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.
*/
package com.iluwatar.acyclicvisitor;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.groups.Tuple.tuple;
import static org.mockito.Mockito.mock;
import static uk.org.lidalia.slf4jext.Level.INFO;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import com.iluwatar.acyclicvisitor.ConfigureForDosVisitor;
import com.iluwatar.acyclicvisitor.Hayes;
import com.iluwatar.acyclicvisitor.HayesVisitor;
import com.iluwatar.acyclicvisitor.Zoom;
import com.iluwatar.acyclicvisitor.ZoomVisitor;
import uk.org.lidalia.slf4jtest.TestLogger;
import uk.org.lidalia.slf4jtest.TestLoggerFactory;
/**
* ConfigureForDosVisitor test class
*/
public class ConfigureForDosVisitorTest {
TestLogger logger = TestLoggerFactory.getTestLogger(ConfigureForDosVisitor.class);
@Test
public void testVisitForZoom() {
ConfigureForDosVisitor conDos = new ConfigureForDosVisitor();
Zoom zoom = new Zoom();
conDos.visit(zoom);
assertThat(logger.getLoggingEvents()).extracting("level", "message").contains(
tuple(INFO, zoom + " used with Dos configurator."));
}
@Test
public void testVisitForHayes() {
ConfigureForDosVisitor conDos = new ConfigureForDosVisitor();
Hayes hayes = new Hayes();
conDos.visit(hayes);
assertThat(logger.getLoggingEvents()).extracting("level", "message").contains(
tuple(INFO, hayes + " used with Dos configurator."));
}
@AfterEach
public void clearLoggers() {
TestLoggerFactory.clear();
}
}

View File

@ -0,0 +1,65 @@
/**
* The MIT License
* Copyright (c) 2014-2016 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.
*/
package com.iluwatar.acyclicvisitor;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.groups.Tuple.tuple;
import static uk.org.lidalia.slf4jext.Level.INFO;
import static org.mockito.Mockito.mock;
import uk.org.lidalia.slf4jtest.TestLogger;
import uk.org.lidalia.slf4jtest.TestLoggerFactory;
import org.junit.jupiter.api.Test;
import com.iluwatar.acyclicvisitor.ConfigureForUnixVisitor;
import com.iluwatar.acyclicvisitor.Hayes;
import com.iluwatar.acyclicvisitor.HayesVisitor;
import com.iluwatar.acyclicvisitor.Zoom;
import com.iluwatar.acyclicvisitor.ZoomVisitor;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
/**
* ConfigureForUnixVisitor test class
*/
public class ConfigureForUnixVisitorTest {
TestLogger logger = TestLoggerFactory.getTestLogger(ConfigureForUnixVisitor.class);
@AfterEach
public void clearLoggers() {
TestLoggerFactory.clear();
}
@Test
public void testVisitForZoom() {
ConfigureForUnixVisitor conUnix = new ConfigureForUnixVisitor();
Zoom zoom = new Zoom();
conUnix.visit(zoom);
assertThat(logger.getLoggingEvents()).extracting("level", "message").contains(
tuple(INFO, zoom + " used with Unix configurator."));
}
}

View File

@ -0,0 +1,60 @@
/**
* The MIT License
* Copyright (c) 2014-2016 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.
*/
package com.iluwatar.acyclicvisitor;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyZeroInteractions;
import org.junit.jupiter.api.Test;
import com.iluwatar.acyclicvisitor.ConfigureForDosVisitor;
import com.iluwatar.acyclicvisitor.ConfigureForUnixVisitor;
import com.iluwatar.acyclicvisitor.Hayes;
import com.iluwatar.acyclicvisitor.HayesVisitor;
/**
* Hayes test class
*/
public class HayesTest {
@Test
public void testAcceptForDos() {
Hayes hayes = new Hayes();
ConfigureForDosVisitor mockVisitor = mock(ConfigureForDosVisitor.class);
hayes.accept(mockVisitor);
verify((HayesVisitor)mockVisitor).visit(eq(hayes));
}
@Test
public void testAcceptForUnix() {
Hayes hayes = new Hayes();
ConfigureForUnixVisitor mockVisitor = mock(ConfigureForUnixVisitor.class);
hayes.accept(mockVisitor);
verifyZeroInteractions(mockVisitor);
}
}

View File

@ -0,0 +1,59 @@
/**
* The MIT License
* Copyright (c) 2014-2016 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.
*/
package com.iluwatar.acyclicvisitor;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.mock;
import org.junit.jupiter.api.Test;
import com.iluwatar.acyclicvisitor.ConfigureForDosVisitor;
import com.iluwatar.acyclicvisitor.ConfigureForUnixVisitor;
import com.iluwatar.acyclicvisitor.Zoom;
import com.iluwatar.acyclicvisitor.ZoomVisitor;
/**
* Zoom test class
*/
public class ZoomTest {
@Test
public void testAcceptForDos() {
Zoom zoom = new Zoom();
ConfigureForDosVisitor mockVisitor = mock(ConfigureForDosVisitor.class);
zoom.accept(mockVisitor);
verify((ZoomVisitor)mockVisitor).visit(eq(zoom));
}
@Test
public void testAcceptForUnix() {
Zoom zoom = new Zoom();
ConfigureForUnixVisitor mockVisitor = mock(ConfigureForUnixVisitor.class);
zoom.accept(mockVisitor);
verify((ZoomVisitor)mockVisitor).visit(eq(zoom));
}
}

133
adapter/README.md Normal file
View File

@ -0,0 +1,133 @@
---
layout: pattern
title: Adapter
folder: adapter
permalink: /patterns/adapter/
categories: Structural
tags:
- Java
- Gang Of Four
- Difficulty-Beginner
---
## Also known as
Wrapper
## Intent
Convert the interface of a class into another interface the clients
expect. Adapter lets classes work together that couldn't otherwise because of
incompatible interfaces.
## Explanation
Real world example
> Consider that you have some pictures in your memory card and you need to transfer them to your computer. In order to transfer them you need some kind of adapter that is compatible with your computer ports so that you can attach memory card to your computer. In this case card reader is an adapter.
> Another example would be the famous power adapter; a three legged plug can't be connected to a two pronged outlet, it needs to use a power adapter that makes it compatible with the two pronged outlet.
> Yet another example would be a translator translating words spoken by one person to another
In plain words
> Adapter pattern lets you wrap an otherwise incompatible object in an adapter to make it compatible with another class.
Wikipedia says
> In software engineering, the adapter pattern is a software design pattern that allows the interface of an existing class to be used as another interface. It is often used to make existing classes work with others without modifying their source code.
**Programmatic Example**
Consider a captain that can only use rowing boats and cannot sail at all.
First we have interfaces `RowingBoat` and `FishingBoat`
```java
public interface RowingBoat {
void row();
}
public class FishingBoat {
private static final Logger LOGGER = LoggerFactory.getLogger(FishingBoat.class);
public void sail() {
LOGGER.info("The fishing boat is sailing");
}
}
```
And captain expects an implementation of `RowingBoat` interface to be able to move
```java
public class Captain implements RowingBoat {
private RowingBoat rowingBoat;
public Captain(RowingBoat rowingBoat) {
this.rowingBoat = rowingBoat;
}
@Override
public void row() {
rowingBoat.row();
}
}
```
Now let's say the pirates are coming and our captain needs to escape but there is only fishing boat available. We need to create an adapter that allows the captain to operate the fishing boat with his rowing boat skills.
```java
public class FishingBoatAdapter implements RowingBoat {
private static final Logger LOGGER = LoggerFactory.getLogger(FishingBoatAdapter.class);
private FishingBoat boat;
public FishingBoatAdapter() {
boat = new FishingBoat();
}
@Override
public void row() {
boat.sail();
}
}
```
And now the `Captain` can use the `FishingBoat` to escape the pirates.
```java
Captain captain = new Captain(new FishingBoatAdapter());
captain.row();
```
## Applicability
Use the Adapter pattern when
* you want to use an existing class, and its interface does not match the one you need
* you want to create a reusable class that cooperates with unrelated or unforeseen classes, that is, classes that don't necessarily have compatible interfaces
* you need to use several existing subclasses, but it's impractical to adapt their interface by subclassing every one. An object adapter can adapt the interface of its parent class.
* most of the applications using third party libraries use adapters as a middle layer between the application and the 3rd party library to decouple the application from the library. If another library has to be used only an adapter for the new library is required without having to change the application code.
## Consequences:
Class and object adapters have different trade-offs. A class adapter
* adapts Adaptee to Target by committing to a concrete Adaptee class. As a consequence, a class adapter wont work when we want to adapt a class and all its subclasses.
* lets Adapter override some of Adaptees behavior, since Adapter is a subclass of Adaptee.
* introduces only one object, and no additional pointer indirection is needed to get to the adaptee.
An object adapter
* lets a single Adapter work with many Adaptees—that is, the Adaptee itself and all of its subclasses (if any). The Adapter can also add functionality to all Adaptees at once.
* makes it harder to override Adaptee behavior. It will require subclassing Adaptee and making Adapter refer to the subclass rather than the Adaptee itself.
## Real world examples
* [java.util.Arrays#asList()](http://docs.oracle.com/javase/8/docs/api/java/util/Arrays.html#asList%28T...%29)
* [java.util.Collections#list()](https://docs.oracle.com/javase/8/docs/api/java/util/Collections.html#list-java.util.Enumeration-)
* [java.util.Collections#enumeration()](https://docs.oracle.com/javase/8/docs/api/java/util/Collections.html#enumeration-java.util.Collection-)
* [javax.xml.bind.annotation.adapters.XMLAdapter](http://docs.oracle.com/javase/8/docs/api/javax/xml/bind/annotation/adapters/XmlAdapter.html#marshal-BoundType-)
## Credits
* [Design Patterns: Elements of Reusable Object-Oriented Software](http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612)
* [J2EE Design Patterns](http://www.amazon.com/J2EE-Design-Patterns-William-Crawford/dp/0596004273/ref=sr_1_2)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB

View File

@ -1,24 +0,0 @@
---
layout: pattern
title: Adapter
folder: adapter
permalink: /patterns/adapter/
categories: Structural
tags: Java
---
**Intent:** Convert the interface of a class into another interface the clients
expect. Adapter lets classes work together that couldn't otherwise because of
incompatible interfaces.
![alt text](./etc/adapter_1.png "Adapter")
**Applicability:** Use the Adapter pattern when
* you want to use an existing class, and its interface does not match the one you need
* you want to create a reusable class that cooperates with unrelated or unforeseen classes, that is, classes that don't necessarily have compatible interfaces
* you need to use several existing subclasses, but it's impractical to adapt their interface by subclassing every one. An object adapter can adapt the interface of its parent class.
**Real world examples:**
* [java.util.Arrays#asList()](http://docs.oracle.com/javase/8/docs/api/java/util/Arrays.html#asList%28T...%29)

View File

@ -1,17 +1,51 @@
<?xml version="1.0"?>
<!--
The MIT License
Copyright (c) 2014-2016 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.
-->
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.6.0</version>
<version>1.20.0-SNAPSHOT</version>
</parent>
<artifactId>adapter</artifactId>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

View File

@ -1,25 +1,60 @@
/**
* The MIT License
* Copyright (c) 2014-2016 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.
*/
package com.iluwatar.adapter;
/**
*
* There are two variations of the Adapter pattern: The class adapter implements
* the adaptee's interface whereas the object adapter uses composition to
* contain the adaptee in the adapter object. This example uses the object
* adapter approach.
* An adapter helps two incompatible interfaces to work together. This is the real world definition
* for an adapter. Interfaces may be incompatible but the inner functionality should suit the need.
* The Adapter design pattern allows otherwise incompatible classes to work together by converting
* the interface of one class into an interface expected by the clients.
*
* <p>
* The Adapter ({@link GnomeEngineer}) converts the interface of the target class
* ({@link GoblinGlider}) into a suitable one expected by the client
* ({@link GnomeEngineeringManager}).
*
* There are two variations of the Adapter pattern: The class adapter implements the adaptee's
* interface whereas the object adapter uses composition to contain the adaptee in the adapter
* object. This example uses the object adapter approach.
*
* <p>
* The Adapter ({@link FishingBoatAdapter}) converts the interface of the adaptee class (
* {@link FishingBoat}) into a suitable one expected by the client ( {@link RowingBoat} ).
*
* <p>
* The story of this implementation is this. <br>
* Pirates are coming! we need a {@link RowingBoat} to flee! We have a {@link FishingBoat} and our
* captain. We have no time to make up a new ship! we need to reuse this {@link FishingBoat}. The
* captain needs a rowing boat which he can operate. The spec is in {@link RowingBoat}. We will
* use the Adapter pattern to reuse {@link FishingBoat}.
*
*/
public class App {
/**
* Program entry point
* @param args command line args
*/
public static void main(String[] args) {
Engineer manager = new GnomeEngineeringManager();
manager.operateDevice();
}
/**
* Program entry point.
*
* @param args command line args
*/
public static void main(String[] args) {
// The captain can only operate rowing boats but with adapter he is able to use fishing boats as well
Captain captain = new Captain(new FishingBoatAdapter());
captain.row();
}
}

View File

@ -0,0 +1,47 @@
/**
* The MIT License
* Copyright (c) 2014-2016 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.
*/
package com.iluwatar.adapter;
/**
* The Captain uses {@link RowingBoat} to sail. <br>
* This is the client in the pattern.
*/
public class Captain {
private RowingBoat rowingBoat;
public Captain() {}
public Captain(RowingBoat rowingBoat) {
this.rowingBoat = rowingBoat;
}
public void setRowingBoat(RowingBoat rowingBoat) {
this.rowingBoat = rowingBoat;
}
public void row() {
rowingBoat.row();
}
}

View File

@ -1,12 +0,0 @@
package com.iluwatar.adapter;
/**
*
* Engineers can operate devices.
*
*/
public interface Engineer {
void operateDevice();
}

View File

@ -0,0 +1,42 @@
/**
* The MIT License
* Copyright (c) 2014-2016 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.
*/
package com.iluwatar.adapter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
* Device class (adaptee in the pattern). We want to reuse this class.
* Fishing boat moves by sailing.
*
*/
public class FishingBoat {
private static final Logger LOGGER = LoggerFactory.getLogger(FishingBoat.class);
public void sail() {
LOGGER.info("The fishing boat is sailing");
}
}

View File

@ -0,0 +1,43 @@
/**
* The MIT License
* Copyright (c) 2014-2016 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.
*/
package com.iluwatar.adapter;
/**
*
* Adapter class. Adapts the interface of the device ({@link FishingBoat}) into {@link RowingBoat}
* interface expected by the client ({@link Captain}).
*
*/
public class FishingBoatAdapter implements RowingBoat {
private FishingBoat boat;
public FishingBoatAdapter() {
boat = new FishingBoat();
}
@Override
public void row() {
boat.sail();
}
}

View File

@ -1,24 +0,0 @@
package com.iluwatar.adapter;
/**
*
* Adapter class. Adapts the interface of the device ({@link GoblinGlider}) into
* {@link Engineer} interface expected by the client ({@link GnomeEngineeringManager}).
*
*/
public class GnomeEngineer implements Engineer {
private GoblinGlider glider;
public GnomeEngineer() {
glider = new GoblinGlider();
}
@Override
public void operateDevice() {
glider.attachGlider();
glider.gainSpeed();
glider.takeOff();
}
}

View File

@ -1,20 +0,0 @@
package com.iluwatar.adapter;
/**
*
* GnomeEngineering manager uses {@link Engineer} to operate devices.
*
*/
public class GnomeEngineeringManager implements Engineer {
private Engineer engineer;
public GnomeEngineeringManager() {
engineer = new GnomeEngineer();
}
@Override
public void operateDevice() {
engineer.operateDevice();
}
}

View File

@ -1,21 +0,0 @@
package com.iluwatar.adapter;
/**
*
* Device class (adaptee in the pattern).
*
*/
public class GoblinGlider {
public void attachGlider() {
System.out.println("Glider attached.");
}
public void gainSpeed() {
System.out.println("Gaining speed.");
}
public void takeOff() {
System.out.println("Lift-off!");
}
}

View File

@ -0,0 +1,34 @@
/**
* The MIT License
* Copyright (c) 2014-2016 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.
*/
package com.iluwatar.adapter;
/**
* The interface expected by the client.<br>
* A rowing boat is rowed to move.
*
*/
public interface RowingBoat {
void row();
}

View File

@ -0,0 +1,78 @@
/**
* The MIT License
* Copyright (c) 2014-2016 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.
*/
package com.iluwatar.adapter;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.util.HashMap;
import java.util.Map;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
/**
* Test class
*
*/
public class AdapterPatternTest {
private Map<String, Object> beans;
private static final String FISHING_BEAN = "fisher";
private static final String ROWING_BEAN = "captain";
/**
* This method runs before the test execution and sets the bean objects in the beans Map.
*/
@BeforeEach
public void setup() {
beans = new HashMap<>();
FishingBoatAdapter fishingBoatAdapter = spy(new FishingBoatAdapter());
beans.put(FISHING_BEAN, fishingBoatAdapter);
Captain captain = new Captain();
captain.setRowingBoat((FishingBoatAdapter) beans.get(FISHING_BEAN));
beans.put(ROWING_BEAN, captain);
}
/**
* This test asserts that when we use the row() method on a captain bean(client), it is
* internally calling sail method on the fishing boat object. The Adapter ({@link FishingBoatAdapter}
* ) converts the interface of the target class ( {@link FishingBoat}) into a suitable one
* expected by the client ({@link Captain} ).
*/
@Test
public void testAdapter() {
Captain captain = (Captain) beans.get(ROWING_BEAN);
// when captain moves
captain.row();
// the captain internally calls the battleship object to move
RowingBoat adapter = (RowingBoat) beans.get(FISHING_BEAN);
verify(adapter).row();
}
}

View File

@ -1,19 +1,38 @@
/**
* The MIT License
* Copyright (c) 2014-2016 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.
*/
package com.iluwatar.adapter;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import com.iluwatar.adapter.App;
import java.io.IOException;
/**
*
* Application test
*
* Tests that Adapter example runs without errors.
*/
public class AppTest {
@Test
public void test() {
String[] args = {};
App.main(args);
}
@Test
public void test() throws IOException {
String[] args = {};
App.main(args);
}
}

View File

@ -0,0 +1,29 @@
---
layout: pattern
title: Aggregator Microservices
folder: aggregator-microservices
permalink: /patterns/aggregator-microservices/
categories: Architectural
tags:
- Java
- Spring
---
## Intent
The user makes a single call to the Aggregator, and the aggregator then calls each relevant microservice and collects
the data, apply business logic to it, and further publish is as a REST Endpoint.
More variations of the aggregator are:
- Proxy Microservice Design Pattern: A different microservice is called upon the business need.
- Chained Microservice Design Pattern: In this case each microservice is dependent/ chained to a series
of other microservices.
![alt text](./etc/aggregator-microservice.png "Aggregator Microservice")
## Applicability
Use the Aggregator Microservices pattern when you need a unified API for various microservices, regardless the client device.
## Credits
* [Microservice Design Patterns](http://blog.arungupta.me/microservice-design-patterns/)

View File

@ -0,0 +1,93 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
The MIT License
Copyright (c) 2014-2016 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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>aggregator-microservices</artifactId>
<groupId>com.iluwatar</groupId>
<version>1.20.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>aggregator-service</artifactId>
<packaging>jar</packaging>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring-boot.version}</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,58 @@
/**
* The MIT License
* Copyright (c) 2014-2016 Ilkka Seppälä
* <p/>
* 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:
* <p/>
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
* <p/>
* 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.
*/
package com.iluwatar.aggregator.microservices;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
/**
* The aggregator aggregates calls on various micro-services, collects
* data and further publishes them under a REST endpoint.
*/
@RestController
public class Aggregator {
@Resource
private ProductInformationClient informationClient;
@Resource
private ProductInventoryClient inventoryClient;
/**
* Retrieves product data.
*
* @return a Product.
*/
@RequestMapping("/product")
public Product getProduct() {
Product product = new Product();
product.setTitle(informationClient.getProductTitle());
product.setProductInventories(inventoryClient.getProductInventories());
return product;
}
}

View File

@ -0,0 +1,42 @@
/**
* The MIT License
* Copyright (c) 2014-2016 Ilkka Seppälä
* <p/>
* 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:
* <p/>
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
* <p/>
* 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.
*/
package com.iluwatar.aggregator.microservices;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* Spring Boot EntryPoint Class
*/
@SpringBootApplication
public class App {
/**
* Program entry point
*
* @param args command line args
*/
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
}

View File

@ -0,0 +1,57 @@
/**
* The MIT License
* Copyright (c) 2014-2016 Ilkka Seppälä
* <p/>
* 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:
* <p/>
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
* <p/>
* 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.
*/
package com.iluwatar.aggregator.microservices;
/**
* Encapsulates all the data for a Product that clients will request.
*/
public class Product {
/**
* The title of the product.
*/
private String title;
/**
* The inventories of the product.
*/
private int productInventories;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public int getProductInventories() {
return productInventories;
}
public void setProductInventories(int productInventories) {
this.productInventories = productInventories;
}
}

View File

@ -0,0 +1,32 @@
/**
* The MIT License
* Copyright (c) 2014-2016 Ilkka Seppälä
* <p/>
* 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:
* <p/>
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
* <p/>
* 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.
*/
package com.iluwatar.aggregator.microservices;
/**
* Interface for the Information micro-service.
*/
public interface ProductInformationClient {
String getProductTitle();
}

View File

@ -0,0 +1,57 @@
/**
* The MIT License
* Copyright (c) 2014-2016 Ilkka Seppälä
* <p/>
* 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:
* <p/>
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
* <p/>
* 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.
*/
package com.iluwatar.aggregator.microservices;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import java.io.IOException;
/**
* An adapter to communicate with information micro-service.
*/
@Component
public class ProductInformationClientImpl implements ProductInformationClient {
private static final Logger LOGGER = LoggerFactory.getLogger(ProductInformationClientImpl.class);
@Override
public String getProductTitle() {
String response = null;
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
HttpGet httpGet = new HttpGet("http://localhost:51515/information");
try (CloseableHttpResponse httpResponse = httpClient.execute(httpGet)) {
response = EntityUtils.toString(httpResponse.getEntity());
}
} catch (IOException e) {
LOGGER.error("Exception caught.", e);
}
return response;
}
}

View File

@ -0,0 +1,31 @@
/**
* The MIT License
* Copyright (c) 2014-2016 Ilkka Seppälä
* <p/>
* 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:
* <p/>
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
* <p/>
* 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.
*/
package com.iluwatar.aggregator.microservices;
/**
* Interface to Inventory micro-service.
*/
public interface ProductInventoryClient {
int getProductInventories();
}

View File

@ -0,0 +1,57 @@
/**
* The MIT License
* Copyright (c) 2014-2016 Ilkka Seppälä
* <p/>
* 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:
* <p/>
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
* <p/>
* 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.
*/
package com.iluwatar.aggregator.microservices;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import java.io.IOException;
/**
* An adapter to communicate with inventory micro-service.
*/
@Component
public class ProductInventoryClientImpl implements ProductInventoryClient {
private static final Logger LOGGER = LoggerFactory.getLogger(ProductInventoryClientImpl.class);
@Override
public int getProductInventories() {
String response = "0";
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
HttpGet httpGet = new HttpGet("http://localhost:51516/inventories");
try (CloseableHttpResponse httpResponse = httpClient.execute(httpGet)) {
response = EntityUtils.toString(httpResponse.getEntity());
}
} catch (IOException e) {
LOGGER.error("Exception caught.", e);
}
return Integer.parseInt(response);
}
}

View File

@ -0,0 +1,24 @@
#
# The MIT License
# Copyright (c) 2014-2016 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.
#
server.port=50004

View File

@ -0,0 +1,70 @@
/**
* The MIT License
* Copyright (c) 2014-2016 Ilkka Seppälä
* <p/>
* 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:
* <p/>
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
* <p/>
* 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.
*/
package com.iluwatar.aggregator.microservices;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.when;
/**
* Test Aggregation of domain objects
*/
public class AggregatorTest {
@InjectMocks
private Aggregator aggregator;
@Mock
private ProductInformationClient informationClient;
@Mock
private ProductInventoryClient inventoryClient;
@BeforeEach
public void setup() {
MockitoAnnotations.initMocks(this);
}
/**
* Tests getting the data for a desktop client
*/
@Test
public void testGetProduct() {
String title = "The Product Title.";
int inventories = 5;
when(informationClient.getProductTitle()).thenReturn(title);
when(inventoryClient.getProductInventories()).thenReturn(inventories);
Product testProduct = aggregator.getProduct();
assertEquals(title, testProduct.getTitle());
assertEquals(inventories, testProduct.getProductInventories());
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

View File

@ -0,0 +1,84 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
The MIT License
Copyright (c) 2014-2016 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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>aggregator-microservices</artifactId>
<groupId>com.iluwatar</groupId>
<version>1.20.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>information-microservice</artifactId>
<packaging>jar</packaging>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring-boot.version}</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,37 @@
/**
* The MIT License
* Copyright (c) 2014-2016 Ilkka Seppälä
* <p/>
* 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:
* <p/>
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
* <p/>
* 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.
*/
package com.iluwatar.information.microservice;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* Inventory Application starts container (Spring Boot) and exposes the Inventory micro-service.
*/
@SpringBootApplication
public class InformationApplication {
public static void main(String[] args) {
SpringApplication.run(InformationApplication.class, args);
}
}

View File

@ -0,0 +1,44 @@
/**
* The MIT License
* Copyright (c) 2014-2016 Ilkka Seppälä
* <p/>
* 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:
* <p/>
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
* <p/>
* 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.
*/
package com.iluwatar.information.microservice;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
/**
* Controller providing endpoints to retrieve information about products
*/
@RestController
public class InformationController {
/**
* Endpoint to retrieve a product's informations.
*
* @return product inventory.
*/
@RequestMapping(value = "/information", method = RequestMethod.GET)
public String getProductTitle() {
return "The Product Title.";
}
}

View File

@ -0,0 +1,24 @@
#
# The MIT License
# Copyright (c) 2014-2016 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.
#
server.port=51515

View File

@ -0,0 +1,43 @@
/**
* The MIT License
* Copyright (c) 2014-2016 Ilkka Seppälä
* <p/>
* 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:
* <p/>
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
* <p/>
* 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.
*/
package com.iluwatar.information.microservice;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* Test for Information Rest Controller
*/
public class InformationControllerTest {
@Test
public void shouldGetProductTitle() {
InformationController infoController = new InformationController();
String title = infoController.getProductTitle();
assertEquals("The Product Title.", title);
}
}

View File

@ -0,0 +1,84 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
The MIT License
Copyright (c) 2014-2016 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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>aggregator-microservices</artifactId>
<groupId>com.iluwatar</groupId>
<version>1.20.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>inventory-microservice</artifactId>
<packaging>jar</packaging>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring-boot.version}</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

Some files were not shown because too many files have changed in this diff Show More