Compare commits

...

807 Commits

Author SHA1 Message Date
Ilkka Seppälä
ba7142ca97 Reach milestone 1.17.0 2017-09-30 22:26:44 +03:00
Narendra Pathai
2f33094030 Merge pull request #645 from amitdash291/patch-1
Removed redundant times(1) params for verify()
2017-09-27 10:18:46 +05:30
Ilkka Seppälä
193879dff6 Merge pull request #641 from dosdebug/fix_command_pattern
Removes unused size and visibility enumerations
2017-09-26 07:35:42 +03:00
Ilkka Seppälä
6848dd020e Merge branch 'master' of https://github.com/iluwatar/java-design-patterns 2017-09-24 19:36:27 +03:00
Ilkka Seppälä
7db7df38fd Fix error in Checkstyle rule definition 2017-09-24 19:36:15 +03:00
Ilkka Seppälä
aa1f57a253 Merge pull request #640 from dosdebug/master
Fixes Checkstyle problems
2017-09-24 19:35:24 +03:00
Ilkka Seppälä
683b45d1b0 Merge pull request #639 from reegnz/fix_naked_objects_url
Fix naked objects thesis url
2017-09-24 19:04:00 +03:00
Ilkka Seppälä
e80677b1f3 Merge pull request #634 from mookkiah/issue_587_promise
#587SonarQube reports bugs in promise module
2017-09-24 18:42:36 +03:00
Amit Dash
a2a08a3a3e Removed redundant times(1) params for verify() 2017-09-24 13:15:42 +05:30
Ilkka Seppälä
fb4c0f77e5 #631 Add missing license header 2017-09-23 09:39:13 +03:00
Ilkka Seppälä
99de0e1644 Merge pull request #636 from gopinath-langote/partial-response-pattern
#631 - Partial response pattern Implementation
2017-09-23 09:35:35 +03:00
Gopinath Langote
dba2d8aef7 #631 - Partial Response : [Refactor] Inline object creation. 2017-09-23 01:03:16 +05:30
Gopinath Langote
06b5c671f5 #631 - Partial Response : Modify AppTest. 2017-09-22 12:33:11 +05:30
Gopinath Langote
c63494cef2 #631 - Partial Response : Modify intendation. 2017-09-22 12:10:15 +05:30
Gopinath Langote
7f9789ce1d #631 - Partial Response : [Refactor] Made Main class name as App for consistancy. 2017-09-22 11:57:12 +05:30
Gopinath Langote
5d8d312733 #631 - Partial Response : Made final private variables in immutable class. 2017-09-22 11:55:21 +05:30
Gopinath Langote
a59e0fa961 #631 - Partial Response : Update copyright header. 2017-09-22 11:53:26 +05:30
Dos Debug
c9f4048301 Removes unused size and visibility enumerations 2017-09-21 20:10:12 +05:00
Dos Debug
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
Ilkka Seppälä
eb36033b83 #590 Add explanation for Chain of Responsibility 2017-09-19 23:20:40 +03:00
Zoltán Reegn
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
Gopinath Langote
06ba337b90 #631 - Partial Response : Add class diagram 2017-09-19 19:00:19 +05:30
Ilkka Seppälä
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
mahendran.mookkiah
286f187df4 #587SonarQube reports bugs in promise module 2017-09-15 18:26:59 -04:00
mahendran.mookkiah
e9579633da #587 SonarQube reports bugs in dao module 2017-09-15 17:39:01 -04:00
Gopinath Langote
91048a49b4 #631 - Partial Response : Add Readme. 2017-09-14 23:07:40 +05:30
Gopinath Langote
fb3a998c04 #631 - Partial Response : Modified puml digram 2017-09-14 22:52:29 +05:30
Gopinath Langote
711f3faf67 #631 - Partial Response : Implement video partial response consuming client. 2017-09-14 22:51:16 +05:30
Gopinath Langote
44e4b3c803 #631 - Partial Response : Implement Field to json conversion 2017-09-14 22:34:02 +05:30
Gopinath Langote
c5b9c63b39 #631 - Partial Response : Add puml file 2017-09-14 21:52:07 +05:30
Gopinath Langote
c89bf0eb44 #631 - Partial Response : Add java doc 2017-09-14 21:50:40 +05:30
Gopinath Langote
6d3dce065d #631 - Partial Response : Get specified fields response. 2017-09-14 19:45:56 +05:30
Gopinath Langote
d0ad0f7ea9 #631 - Partial Response : Add missing length in video details 2017-09-14 19:35:52 +05:30
Gopinath Langote
a0c081f5ea #631 - Partial Response : Return video details as json string. 2017-09-14 19:27:46 +05:30
Gopinath Langote
b7dbb4049c #631 - Partial Response : [Refactor] Modify video model fields. 2017-09-14 19:15:44 +05:30
Gopinath Langote
87d4853846 #631 - Partial Response : [Refactor] Rename GetDetails method by id. 2017-09-14 18:47:46 +05:30
Ilkka Seppälä
5836fdb54b Merge pull request #632 from OCNYang/master
Delete duplicate declared objects:ClubbedTroll
2017-09-14 08:10:41 +03:00
Gopinath Langote
f38119c565 #631 - Partial Response : Get video details by id. 2017-09-14 10:09:02 +05:30
Gopinath Langote
5828ef9dd1 #631 - Partial Response : Get video details by id. 2017-09-14 10:08:56 +05:30
OCN.Yang
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
Ilkka Seppälä
2e90f82cab #590 Add explanation for Proxy pattern 2017-09-13 21:07:10 +03:00
Ilkka Seppälä
f9d1e9aa3f Update Throttling pattern readme 2017-09-13 20:39:31 +03:00
Gopinath Langote
7ca5342819 #631 - Partial Response : Add video model. 2017-09-13 22:58:34 +05:30
Gopinath Langote
263534caab #631 - Partial Response : Added module to project. 2017-09-13 22:34:26 +05:30
Gopinath Langote
8652d0d32b Merge remote-tracking branch 'upstream/master' 2017-09-13 22:15:26 +05:30
Ilkka Seppälä
a8f2e70e0a Alter Throttling pattern display name 2017-09-13 08:22:29 +03:00
Ilkka Seppälä
4e290416df Merge pull request #629 from rastdeepanshu/throttling-pattern
Throttling pattern
2017-09-11 22:30:11 +03:00
Gopinath Langote
565d5a0129 Merge remote-tracking branch 'upstream/master' 2017-09-11 01:16:32 +05:30
Deepanshu Rastogi
50d7dbe4de Seperated timer class and created Callscount class 2017-09-08 16:15:31 +02:00
Deepanshu Rastogi
5f9100cd03 Adding class diag and updating readme 2017-09-07 15:27:18 +02:00
Deepanshu Rastogi
2cf773e550 Adding etc with ucls and puml 2017-09-07 15:14:17 +02:00
Deepanshu Rastogi
05629f687b Adding throttling pattern 2017-09-07 12:54:19 +02:00
Ilkka Seppälä
c13661810e #590 Add explanation for Flyweight 2017-09-06 22:31:21 +03:00
Ilkka Seppälä
bd4247e864 #590 Add explanation for Facade pattern 2017-09-05 23:28:44 +03:00
Ilkka Seppälä
a745c5d8ce Update .gitignore 2017-09-03 12:06:50 +03:00
Ilkka Seppälä
efc6eb8828 Merge pull request #610 from radresian/event-sourcing
Event sourcing
2017-09-03 11:46:11 +03:00
Ilkka Seppälä
9d2f0c6c71 #590 Add explanation to Decorator pattern 2017-09-02 23:10:39 +03:00
Serdar Hamzaoğulları
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
Ilkka Seppälä
6c9e005a79 Merge pull request #623 from danielsiwiec/master
Make toString synchronized. Closes #621
2017-09-01 08:55:59 +03:00
Ilkka Seppälä
d8e779a7b2 Merge pull request #624 from josejhgjghjghjghjghj/patch-1
Delete postPumlsToServer.firstrun.output
2017-09-01 08:38:17 +03:00
josejhgjghjghjghjghj
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
Dan Siwiec
a3324a122c Make toString synchronized. Closes #621 2017-08-31 18:28:27 -07:00
Ilkka Seppälä
f28ed7b46e #590 Add explanation for Composite pattern 2017-08-31 22:11:58 +03:00
Ilkka Seppälä
7f1fac036e Merge pull request #622 from crowchirp/master
corrected typos
2017-08-31 08:21:30 +03:00
Chandan Rai
08cc50e875 corrected typos 2017-08-31 01:50:33 +05:30
Gopinath Langote
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
Ilkka Seppälä
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
Ilkka Seppälä
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
Ilkka Seppälä
f80d917432 Merge pull request #619 from iluwatar/bridge
Improved bridge example and added explanation
2017-08-23 21:33:00 +03:00
Ilkka Seppälä
1dc038bc30 Add explanation for Bridge pattern 2017-08-23 21:25:48 +03:00
Ilkka Seppälä
6f1736d2e6 Refactored tests for Bridge 2017-08-22 22:01:52 +03:00
Gopinath Langote
2a98a1399e #348 - Data Tranfer Object : Add Puml id to README.md. 2017-08-22 14:21:05 +05:30
Ilkka Seppälä
a5ec376089 Work on improved Bridge example 2017-08-22 09:11:18 +03:00
Serdar Hamzaoğulları
82d7e57e8e Integration Test 2017-08-19 22:06:35 +03:00
Hasan Serdar Hamzaoğulları
671230d798 Merge branch 'master' into event-sourcing 2017-08-19 14:00:04 +03:00
Ilkka Seppälä
ed1a0022b9 #596 Add more logging to Reactor 2017-08-19 11:00:34 +03:00
Ilkka Seppälä
5db6776971 #590 Fix PMD issue 2017-08-19 10:10:49 +03:00
Ilkka Seppälä
fbf5ffe67a #590 Add explanation for Adapter 2017-08-19 10:00:18 +03:00
mahendran.mookkiah
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
Ilkka Seppälä
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
mahendran.mookkiah
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
Ilkka Seppälä
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
Ilkka Seppälä
e367e48ec2 Merge pull request #608 from gopinath-langote/master
#348 Data Transfer Object design pattern
2017-08-17 22:15:38 +03:00
Ilkka Seppälä
b639f3630e #590 Add explanation for Prototype 2017-08-16 21:09:28 +03:00
Gopinath Langote
f9789d6926 #348 - Data Tranfer Object : Add class diagram. 2017-08-14 16:14:23 +05:30
Gopinath Langote
4a81453da4 #348 - Data Tranfer Object : Make private varialbes final in immutalbe model. 2017-08-14 00:46:31 +05:30
Gopinath Langote
b62d431d62 #348 - Data Tranfer Object : Use logger instead of print statements. 2017-08-14 00:40:29 +05:30
Gopinath Langote
8525bfd323 #348 - Data Tranfer Object : Add dto module to main pom.xml 2017-08-14 00:40:01 +05:30
Gopinath Langote
9c088b5f47 #348 - Data Tranfer Object : Mofidy maven dependancies. 2017-08-14 00:23:03 +05:30
Gopinath Langote
3eab4d75a6 Revert "#348 - Data Tranfer Object : Added module to project."
This reverts commit db10b937f2.
2017-08-14 00:16:29 +05:30
Ilkka Seppälä
f6c8bfbc39 #590 Add explanation for Builder 2017-08-13 17:34:05 +03:00
mahendran.mookkiah
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
Ilkka Seppälä
cbba487ff8 Merge branch 'master' of https://github.com/iluwatar/java-design-patterns 2017-08-13 10:09:46 +03:00
Ilkka Seppälä
37b9d45a74 #590 Add explanation for Abstract Factory 2017-08-13 10:09:26 +03:00
Ilkka Seppälä
2e99cb41ad Merge pull request #605 from mookkiah/587_model-view-presenter
#587 SonarQube reports bugs
2017-08-13 08:57:13 +03:00
Serdar Hamzaoğulları
eb2a232382 README edited 2017-08-13 01:36:52 +03:00
Serdar Hamzaoğulları
4b3435c550 Code formating 2017-08-13 00:08:35 +03:00
Ilkka Seppälä
fba30e59ee #590 Kramdown fixes 2017-08-12 21:44:21 +03:00
Ilkka Seppälä
2d750dc0fd #590 Alter Factory Method presentation 2017-08-12 20:02:14 +03:00
Ilkka Seppälä
002774b5aa Fix Travis out of memory error 2017-08-12 19:24:55 +03:00
Ilkka Seppälä
2150a2bb55 #590 Skip puml processing for singleton module 2017-08-12 18:42:14 +03:00
Ilkka Seppälä
746e452c2b #590 Add new presentation for Singleton 2017-08-12 18:20:45 +03:00
Ilkka Seppälä
600553ec0f Merge pull request #583 from shaiktaj/patch-1
Updated ThreadSafeLazyLoadedivoryTower
2017-08-12 16:58:01 +03:00
Serdar Hamzaoğulları
64824d65aa Some Object Orianted refactor 2017-08-12 16:21:35 +03:00
Gopinath Langote
bfbc8fd740 #348 - Data Tranfer Object : Add readme.md 2017-08-11 16:51:46 +05:30
Gopinath Langote
df9be78504 #348 - Data Tranfer Object : customer client request customer details to server at one shot. 2017-08-11 16:17:51 +05:30
Gopinath Langote
229fda9f3c #348 - Data Tranfer Object : Add puml diagram. 2017-08-11 15:55:12 +05:30
Gopinath Langote
148de06bb1 #348 - Data Tranfer Object : Implement Data Transfer Object pattern simple version. 2017-08-11 15:42:21 +05:30
Gopinath Langote
67d4477d25 #348 - Data Tranfer Object : Add puml file to etc. 2017-08-10 13:45:46 +05:30
Gopinath Langote
db10b937f2 #348 - Data Tranfer Object : Added module to project. 2017-08-09 15:27:36 +05:30
Serdar Hamzaoğulları
1474a50e5e Example done with app class 2017-08-06 22:51:43 +03:00
Serdar Hamzaoğulları
9f612ecfda first commit 2017-08-05 23:33:08 +03:00
mahendran.mookkiah
0271e55983 #587 SonarQube reports bugs 2017-08-05 10:07:28 -04:00
Ilkka Seppälä
54d8ec94be Merge pull request #599 from mookkiah/587_intercepting-filter
#587 sonarqube bugs
2017-07-30 08:49:17 +03:00
Ilkka Seppälä
ffbf56f01a CQRS pattern: Add missing license headers 2017-07-29 21:41:11 +03:00
Ilkka Seppälä
83fcbe0713 Merge pull request #603 from kevelbreh/patch-1
Update README.md punctuation and spelling
2017-07-29 21:13:29 +03:00
Ilkka Seppälä
0982f00a61 Merge pull request #595 from isabiq/master
CQRS pattern
2017-07-29 20:45:55 +03:00
Sabiq Ihab
871df4f918 close connection before throwing an exception 2017-07-29 13:26:54 +01:00
Sabiq Ihab
7ae9e3ee22 add a description of the pattern 2017-07-29 13:13:08 +01:00
Sabiq Ihab
c572fe885e add check on null objects 2017-07-29 12:16:19 +01:00
Sabiq Ihab
a221245909 Use Logger instead of println 2017-07-29 12:14:15 +01:00
Sabiq Ihab
8bf4497879 Close sessions using try with resources 2017-07-29 12:13:34 +01:00
Sabiq Ihab
8073b93182 fix README.md 2017-07-29 12:04:04 +01:00
Kevin Woodland
9b1a9aafc1 Update README.md punctuation and spelling
Fixed minor punctuation and spelling while reading through applicability
2017-07-28 20:20:38 +02:00
mahendran.mookkiah
c6b6c8123f #587 sonarqube bugs 2017-07-22 18:35:18 -04:00
Sabiq Ihab
87c10faaac Fix : remove AppTest 2017-06-30 23:22:44 +00:00
Sabiq Ihab
d1b11539ec add pumlid 2017-06-30 21:53:47 +00:00
Sabiq Ihab
c744bf418a add README.md, cqrs.ucls and etc/cqrs.urm.puml 2017-06-30 21:41:25 +00:00
Sabiq Ihab
5873aeeb69 add cqrs module to parent pom.xml and update pom.xml 2017-06-30 21:31:25 +00:00
Sabiq Ihab
d8919d88f0 fix pmd errors 2017-06-30 21:26:02 +00:00
Sabiq Ihab
b67719ab32 add tests 2017-06-30 21:26:02 +00:00
Sabiq Ihab
a8f50297eb add hashCode and equals to Author and Book DTOs 2017-06-30 21:26:02 +00:00
Sabiq Ihab
3128d3fb40 create main class 2017-06-30 21:26:02 +00:00
Sabiq Ihab
a2dba5bf6d add logs, javadoc and format to checkstyle conventions 2017-06-30 21:26:02 +00:00
Sabiq Ihab
40c00ca2af add ICommandService and IQueriesService Implementations 2017-06-30 21:26:02 +00:00
Sabiq Ihab
8e25ec55bf change long with BigIntger and replace getBook() 2017-06-30 21:26:02 +00:00
Sabiq Ihab
8881950e6d add toString() to BookDTO 2017-06-30 21:26:02 +00:00
Sabiq Ihab
51bcee5d7d add Queries and Commands Interfaces 2017-06-30 21:26:02 +00:00
Sabiq Ihab
15a25f0ef3 add DTOs 2017-06-30 21:26:02 +00:00
Sabiq Ihab
f3902ffc16 add setters and protected no-arg constructor 2017-06-30 21:26:02 +00:00
Sabiq Ihab
8208f6252b add hibernate.cfg and HibernateUtil class 2017-06-30 21:26:02 +00:00
Sabiq Ihab
ca73621f4d create data model 2017-06-30 21:26:01 +00:00
Sabiq Ihab
4e9988877a Initial commit 2017-06-30 21:26:01 +00:00
Ilkka Seppälä
ac721c695c Set version for next development iteration 2017-06-30 20:33:29 +03:00
Ilkka Seppälä
d793160bce Reach milestone 1.16.0 2017-06-30 20:31:31 +03:00
Ilkka Seppälä
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
Harshrajsinh Thakor
edea7d2220 Refactored Function<Integer,T> to IntFunction<T>. 2017-06-14 11:58:05 -07:00
Ilkka Seppälä
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
Ilkka Seppälä
d13635533a Merge pull request #588 from prafful1/master
Few additions in readme
2017-06-14 20:14:09 +03:00
Ilkka Seppälä
37cd4cbb3b Merge pull request #585 from fluency03/master
add RxJava to Real world examples of observer
2017-06-14 20:12:32 +03:00
Ilkka Seppälä
3d29755842 Add license headers 2017-06-11 19:37:52 +03:00
Ilkka Seppälä
5b47d48fc2 Merge pull request #573 from SrdjanPaunovic/extension-objects
#541 Extension objects pattern
2017-06-11 19:26:47 +03:00
Harshrajsinh Thakor
73934e25e5 Refactored the Functional Interface to the Specialized Functional
Interface.
2017-06-09 17:17:56 -07:00
prafful1
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
Srđan Paunović
a0916aab6c Update README.md 2017-06-04 21:12:30 +02:00
SrdjanPaunovic
863589ed29 Create meaningful JavaDocs instead of author names 2017-06-04 21:09:17 +02:00
SrdjanPaunovic
85acb1cf6c Replase system.println with logger 2017-06-04 20:49:15 +02:00
Srđan Paunović
09fb79099f Merge branch 'master' into extension-objects 2017-06-02 21:50:00 +02:00
SrdjanPaunovic
22a7c15acc Reset execute-around/pom.xml from master 2017-06-02 21:42:59 +02:00
Chang Liu
0182b840af add RxJava to Real world examples of observer 2017-05-30 13:22:52 +02:00
Ilkka Seppälä
f87249e03b Add missing license headers 2017-05-29 21:53:05 +03:00
Ilkka Seppälä
dd0ca2d16e Merge pull request #572 from 4lexis/master
#567 Marker Interface pull request
2017-05-29 21:41:27 +03:00
shaiktaj
24f258848c Updated ThreadSafeLazyLoadedivoryTower
Added null check in private constructor to prevent instantiating by Reflection call
2017-05-25 11:04:30 -05:00
Aleksandar Dudukovic
f2e35ec03d #567 fix version and javadoc 2017-05-23 01:38:02 +02:00
Ilkka Seppälä
ae1d9cf7a8 Add missing license headers 2017-05-21 09:19:29 +03:00
Ilkka Seppälä
1bbc597671 Merge pull request #575 from prafful1/master
Few additions in README
2017-05-21 09:11:00 +03:00
Ilkka Seppälä
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
kapinuss
17039dc5e9 Update AdvancedSorceressTest.java 2017-05-18 20:27:16 +03:00
kapinuss
30dcbee2cc Update AdvancedSorceress.java 2017-05-18 20:26:47 +03:00
kapinuss
08901f3c26 Update AdvancedSorceress.java 2017-05-18 20:23:05 +03:00
kapinuss
c746004f73 Update AdvancedSorceress.java 2017-05-18 19:13:45 +03:00
kapinuss
09aa44ddcb Update App.java 2017-05-18 19:13:09 +03:00
Ilkka Seppälä
992e76ac61 Merge pull request #566 from qpi/master
Event Queue pattern
2017-05-16 21:59:50 +03:00
Mihály Kuprivecz
167a43f72e updated model.png 2017-05-15 11:04:41 +02:00
Mihály Kuprivecz
fe1e45bd69 some fixes 2017-05-15 10:40:12 +02:00
Ilkka Seppälä
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
Mihály Kuprivecz
0546223bba quick fix 2017-05-11 21:44:07 +02:00
Mihály Kuprivecz
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
Ilkka Seppälä
0b57edd211 Merge pull request #568 from brandon-d-mckay/patch-1
Fix incorrect URL
2017-05-09 23:10:31 +03:00
prafful1
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
Srđan Paunović
6857486f27 #541 Create README.md file 2017-05-04 12:33:25 +02:00
Aleksandar Dudukovic
1abd96a9c8 #567 checkstyle fix 2017-05-03 22:09:47 +02:00
SrdjanPaunovic
08c4202852 #541 fix checkstyle errors 2017-05-03 22:08:04 +02:00
Aleksandar Dudukovic
6ecf994258 #567 pom.xml align fix 2017-05-03 21:42:15 +02:00
SrdjanPaunovic
0687a3f9f8 #541 pom.xml fix align 2017-05-03 21:40:54 +02:00
Aleksandar Dudukovic
64337dff06 merge fix 2017-05-03 21:07:49 +02:00
4lexis
34b09c75ec #567 added .gitignore 2017-05-03 20:51:51 +02:00
4lexis
66c6f30c1c #567 Updated pom.xml 2017-05-03 20:34:27 +02:00
Aleksandar Dudukovic
e413b116ac Merge branch 'master' of https://github.com/4lexis/java-design-patterns 2017-05-03 19:57:57 +02:00
Aleksandar Dudukovic
6e0b3e37ea updated pom.xml 2017-05-03 19:57:14 +02:00
4lexis
be3f4dce50 Update Picture 2017-05-03 19:49:25 +02:00
4lexis
6d87f63ed5 Added README.md 2017-05-03 19:48:29 +02:00
SrdjanPaunovic
c92a8daeda Class diagram & fix relation between units 2017-05-03 17:59:54 +02:00
Aleksandar Dudukovic
20062faae6 All without Readme and pumlid 2017-05-03 17:50:35 +02:00
SrdjanPaunovic
678524704c Test done 2017-05-03 13:21:13 +02:00
kapinuss
2b229d8ea1 Update AdvancedSorceressTest.java 2017-05-02 20:38:08 +03:00
kapinuss
03aa99c55f Update AdvancedSorceressTest.java 2017-05-02 20:18:05 +03:00
ytian90
20a4c054a7 Merge branch 'master' of github.com:ytian90/java-design-patterns 2017-04-30 00:20:48 -07:00
ytian90
3ed6cc19d2 fix Block 3 case 2017-04-30 00:19:50 -07:00
Yu Tian
87a9387e62 Merge pull request #1 from iluwatar/master
Rebase
2017-04-29 16:03:26 -07:00
Aleksandar Dudukovic
8530d01e10 code implemented 2017-04-29 16:35:57 +02:00
Aleksandar Dudukovic
a34e7be9c2 check commit 2017-04-28 19:35:19 +02:00
Mihály Kuprivecz
ee3744cb0a added travis supported sound files 2017-04-28 13:47:56 +02:00
Mihály Kuprivecz
2830a407ba some fixes for testing in event queue 2017-04-28 12:19:57 +02:00
kapinuss
ccfb6709c7 Add files via upload 2017-04-28 13:00:01 +03:00
kapinuss
a1c5131304 Add files via upload 2017-04-28 12:59:09 +03:00
Mihály Kuprivecz
44401988d1 pom.xml fixes 2017-04-28 11:32:35 +02:00
Mihály Kuprivecz
6e8eaf7593 adding some test cases for the event queue 2017-04-28 10:38:40 +02:00
SrdjanPaunovic
645e91ed23 first version of pattern without Tests 2017-04-27 13:58:58 +02:00
Brandon D. McKay
9e7e8a64f6 Fix incorrect URL 2017-04-26 04:22:44 -04:00
Mihály Kuprivecz
152b2762c3 read.me and the diagram is added 2017-04-22 17:16:38 +02:00
Ilkka Seppälä
82b9f4fea7 Merge pull request #544 from kemitix/data-bus
[WIP] Data Bus
2017-04-22 15:17:31 +03:00
Paul Campbell
ff8d854a8d #467 data-bus: README.md: clean up 2017-04-16 06:51:10 +01:00
Ilkka Seppälä
31f4b15e86 Merge pull request #565 from kapinuss/patch-1
Update ObjectPool.java
2017-04-16 08:17:56 +03:00
Ilkka Seppälä
cd54cf5512 Merge pull request #563 from sunilmogadati/SonarQubeBlockerBugs
#507 SonarQube blocker severity bugs
2017-04-16 08:13:26 +03:00
kapinuss
798aee47b3 Update ObjectPool.java 2017-04-12 18:59:43 +03:00
Mihály Kuprivecz
dce767c1c5 first commit 2017-04-06 23:48:15 +02:00
Sunil Mogadati
60ebcc56f8 #507 SonarQube blocker severity bugs 2017-04-01 20:55:47 -06:00
Paul Campbell
2643dfa0b8 #467 data-bus: App: add notes about this implementation of the patter 2017-04-01 19:33:54 +01:00
Paul Campbell
c96ebcb197 #467 data-bus: App: add description of the pattern 2017-04-01 19:26:41 +01:00
Paul Campbell
b72d545349 #467 data-bus: members: StatusMemberTest: added 2017-04-01 19:17:09 +01:00
Paul Campbell
311bb79870 #467 data-bus: members: StatusMember: records start and stop times 2017-04-01 19:16:55 +01:00
Paul Campbell
f495a88e91 #467 data-bus: members: MessageCollectorMemberTest: added 2017-04-01 19:05:19 +01:00
Paul Campbell
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
Paul Campbell
b7a6a018e0 #467 data-bus: DataBusTest: added 2017-04-01 18:36:04 +01:00
Paul Campbell
46e0fa4825 #467 data-bus: pom.xml: add mockito dependency 2017-04-01 18:35:40 +01:00
Paul Campbell
86009f2261 #467 data-bus: add missing javadoc 2017-04-01 18:12:56 +01:00
Paul Campbell
146f367188 #467 data-bus: remove lombok 2017-04-01 18:12:32 +01:00
Paul Campbell
bc4d029a87 #467 data-bus: pom.xml: remove surefire plugin 2017-04-01 18:04:44 +01:00
Paul Campbell
960eee3d43 #467 update version 2017-04-01 18:04:16 +01:00
Paul Campbell
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
Ilkka Seppälä
073d06c0ae Set version for next development iteration 2017-04-01 17:15:59 +03:00
Ilkka Seppälä
8fea969912 Reached milestone 1.15.0 2017-04-01 17:14:02 +03:00
Ilkka Seppälä
139876f96a #539 Checkstyle fix 2017-04-01 15:51:01 +03:00
Ilkka Seppälä
f3c4640d12 #539 More Checkstyle fixes 2017-04-01 15:43:36 +03:00
Ilkka Seppälä
c1c4411957 #539 Checkstyle fixes 2017-04-01 15:34:13 +03:00
Ilkka Seppälä
3f272bf291 Merge pull request #548 from muditporwal/master
Checkstyle improvements #539 : Added JavaDocType Rule
2017-04-01 14:45:52 +03:00
Ilkka Seppälä
2921448f8b #497 Add missing puml and license headers 2017-04-01 14:25:13 +03:00
Ilkka Seppälä
952c207a62 Merge pull request #546 from Crossy147/converter
Converter
2017-04-01 14:17:37 +03:00
Ilkka Seppälä
6ba4d7be98 #77 Add missing license header 2017-04-01 12:39:06 +03:00
Ilkka Seppälä
854101bb49 Merge pull request #529 from thomasoss/master
Thread Local Storage issue #77
2017-04-01 12:29:03 +03:00
Kamil Pietruszka
a5ab5c7d8e Merge branch 'master' into converter 2017-03-26 23:50:08 +02:00
Ilkka Seppälä
286d6c3a4c Merge pull request #536 from Rzeposlaw/master
#66 Balking Pattern
2017-03-26 15:00:21 +03:00
NooBxGockeL
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
Mudit Porwal
09585c3874 Removed AvoidStarImport Rule
Added JavaDocType Rule
2017-03-22 01:16:02 +08:00
Thomas
f84c4c1611 Update App.java
Correction of correction ;-)
2017-03-18 10:02:37 +01:00
Thomas
2c2d874ac8 Update App.java
Correction of error detected by maven-pmd-plugin.
2017-03-18 10:00:13 +01:00
Kamil Pietruszka
72a0765ec6 Merge branch 'master' into converter 2017-03-16 12:27:05 +01:00
Katarzyna Rzepecka
cca4d5a670 Update after changes from review. Additional improvements. 2017-03-13 01:33:14 +01:00
Katarzyna Rzepecka
bb4a1bdc05 Pom.xml files fixed. 2017-03-13 01:16:26 +01:00
Katarzyna Rzepecka
1aed5905d7 #66 Balking Pattern 2017-03-13 01:15:39 +01:00
Ilkka Seppälä
175e9f58c1 Merge pull request #537 from robertt240/master
guarded suspension pattern #69
2017-03-12 10:36:27 +02:00
Kamil Pietruszka
77a534385c fixed pmd violation 2017-03-11 13:35:55 +01:00
Kamil Pietruszka
2ed7acbc31 fixed checkstyle violations 2017-03-11 13:02:29 +01:00
Kamil Pietruszka
3a243eee6e diagrams added 2017-03-11 12:47:58 +01:00
Kamil Pietruszka
8632bafcd7 comments, tests and description 2017-03-11 12:24:48 +01:00
Robert Kasperczyk
449aed1a53 changed parent POM version #69 2017-03-11 12:02:04 +01:00
Robert Kasperczyk
a20abae21c apply changes from review #69 2017-03-11 11:50:19 +01:00
Robert Kasperczyk
7423f47daa further POM rearragments #69 2017-03-11 11:50:19 +01:00
Robert Kasperczyk
f09578c091 further POM rearragments #69 2017-03-11 11:50:19 +01:00
Robert Kasperczyk
29715028d1 fix in POM formatting #69 2017-03-11 11:50:19 +01:00
Robert Kasperczyk
e5034c6ae9 guarded suspension pattern #69 2017-03-11 11:50:19 +01:00
Robert Kasperczyk
a09866d35b another readme fix 2017-03-11 11:50:19 +01:00
Robert Kasperczyk
1824b4138b readme fix 2017-03-11 11:50:19 +01:00
Robert Kasperczyk
764ff4bf53 Initial commit of guarded suspension design pattern 2017-03-11 11:50:19 +01:00
Kamil Pietruszka
e8b634c33e java docs added 2017-03-10 20:59:24 +01:00
Kamil Pietruszka
8871f788d2 #497 Converter pattern implementation 2017-03-10 20:08:58 +01:00
Kamil Pietruszka
e9c54011e9 Merge remote-tracking branch 'refs/remotes/iluwatar/master' 2017-03-08 16:50:04 +01:00
Paul Campbell
6b795e52c3 #467 data-bus: README.md: updated for data-bus 2017-03-05 19:43:57 +00:00
Paul Campbell
b5bdf2d7d7 #467 data-bus: etc: add urm diagrams 2017-03-05 19:43:26 +00:00
Paul Campbell
3fd6887975 #467 data-bus: implement pattern 2017-03-05 18:55:34 +00:00
Paul Campbell
eecffb0ea5 #467 data-bus: add stub 2017-03-03 19:58:03 +00:00
Thomas
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
Ilkka Seppälä
cca4760f69 #190 Rename package for Queue-Based Load Leveling pattern 2017-02-12 00:33:30 +02:00
Ilkka Seppälä
a1ff55b462 #190 Regenerate puml files 2017-02-11 21:46:56 +02:00
Thomas
ddac9dc6cb Add files via upload
Changed the classname part "runnable" to "callable"
2017-01-29 12:34:13 +01:00
Thomas
2bbf84233e Delete DateFormatRunnableTestMultiThread.java 2017-01-29 12:32:44 +01:00
Thomas
82f8460243 Delete DateFormatRunnableTestIncorrectDateFormat.java 2017-01-29 12:32:32 +01:00
Thomas
59ea20745f Delete DateFormatRunnableTest.java 2017-01-29 12:32:21 +01:00
Thomas
3d3dd58501 Update pom.xml
removed errors caused by copy code from master
2017-01-29 12:08:11 +01:00
Thomas
3324e1bc43 Update pom.xml
added  <module>tls</module>
2017-01-29 12:01:32 +01:00
Thomas
6202f3ab44 Add files via upload 2017-01-29 11:42:16 +01:00
Thomas
453862cfc2 Delete AppTest.java 2017-01-29 11:41:46 +01:00
Thomas
a8e2c157de Add files via upload
Test reworked completely. AppTest seperated.
2017-01-29 11:41:13 +01:00
Thomas
080965fb17 Delete DateFormatUglyRunnable.java 2017-01-29 11:38:49 +01:00
Thomas
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
Thomas
f170aaa42b Delete DateFormatRunnable.java 2017-01-29 11:34:12 +01:00
Thomas
c598748549 Delete AppUgly.java 2017-01-29 11:33:59 +01:00
Thomas
ed11c4c4f9 Delete App.java 2017-01-29 11:33:40 +01:00
Thomas
283f198ba8 Delete empty 2017-01-29 11:32:26 +01:00
Thomas
15913d6382 Add files via upload
new uml diagramm after changes to the java classes
2017-01-29 11:31:06 +01:00
Thomas
65e047974c Create empty 2017-01-29 11:29:19 +01:00
Thomas
c529e35791 Delete tls.urm.puml 2017-01-29 11:28:27 +01:00
Thomas
3342851005 Delete tls.ucls 2017-01-29 11:28:17 +01:00
Thomas
c167f87ce5 Delete tls.png 2017-01-29 11:27:46 +01:00
Thomas
e8fc3427c6 Update README.md
no change of content. Improved text
2017-01-29 11:23:33 +01:00
Thomas
26b79a5382 Update README.md
Some additonal description, deleted wrong pumlid
2017-01-29 11:16:45 +01:00
Ilkka Seppälä
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
leogtzr
c6d0d28557 Reverting initialization on demand holder idiom. 2017-01-22 11:06:57 -07:00
leogtzr
e26215578c Changing code to use interfaces instead of implementations. 2017-01-21 15:49:29 -07:00
leogtzr
d6fc28e120 Changing code to use interfaces instead of implementations. 2017-01-21 15:47:54 -07:00
Ilkka Seppälä
115a85301c #525 Add link to proxy blog 2017-01-21 13:37:16 +02:00
Ilkka Seppälä
29c5b80f19 #525 Add link to Queue-Based Load Leveling blog 2017-01-21 12:56:42 +02:00
Ilkka Seppälä
0c8bb1c22e Set version for next development iteration 2016-12-31 10:24:26 +02:00
Ilkka Seppälä
0c48695fa5 Achieved milestone 1.14.0 2016-12-31 10:23:32 +02:00
Ilkka Seppälä
8d34ccf827 Add link to Proxy presentation. 2016-12-26 20:16:30 +02:00
Ilkka Seppälä
512a5c0560 Merge branch 'proxy-presentation' 2016-12-26 20:08:41 +02:00
Ilkka Seppälä
9cf1918425 Add presentation for Proxy pattern. 2016-12-26 20:05:38 +02:00
Ilkka Seppälä
5e57cd03d1 Add some material for proxy presentation. 2016-12-26 19:43:46 +02:00
leogtzr
6292690250 Changing constant interface pattern with a Noninstantiable class 2016-12-24 14:49:41 -07:00
Ilkka Seppälä
ad93184a79 Merge pull request #530 from Valdar-Soft/master
Sonar quality bugfix and minor refactor
2016-12-24 12:36:11 +02:00
leogtzr
20b1c2bd49 Adding initialization on demand holder idiom. 2016-12-24 00:49:46 -07:00
Krisztián Nagy
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
Krisztián Nagy
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
Thomas
e210e4ed62 Add files via upload 2016-12-16 11:17:27 +01:00
Thomas
fb98da86c4 Add files via upload 2016-12-16 11:12:43 +01:00
Thomas
c8b3c773c7 Add files via upload 2016-12-16 09:43:16 +01:00
Thomas
61b1356976 Delete emptyfile 2016-12-16 09:42:46 +01:00
Thomas
487f9ddc80 Add files via upload 2016-12-16 09:42:08 +01:00
Thomas
9b7ce556e3 Create emptyfile 2016-12-16 09:35:19 +01:00
Thomas
e17cf27e5a upload pom.xml 2016-12-15 18:33:52 +01:00
Thomas
937a1e269d delete empty file 2016-12-15 18:32:13 +01:00
Thomas
803a97237c delete empty file 2016-12-15 18:31:53 +01:00
Thomas
e64f7faa3f upload junit test 2016-12-15 18:31:20 +01:00
Thomas
15d660b117 empty file to create folder 2016-12-15 18:30:22 +01:00
Thomas
544f7fb6d1 delete empty file 2016-12-15 18:28:02 +01:00
Thomas
c4eb198a8d Upload code files 2016-12-15 18:27:28 +01:00
Thomas
7067d1ae56 Create test 2016-12-15 18:24:03 +01:00
Thomas
d80edd1ed3 Create test 2016-12-15 18:08:12 +01:00
Thomas
aeefc11f25 Merge pull request #1 from iluwatar/master
Update my local repository
2016-12-14 08:52:22 +01:00
Ilkka Seppälä
c94c8a3e74 Merge pull request #512 from inbravo/master
Module pattern #62
2016-12-01 20:53:12 +02:00
Amit Dixit
5d8806858b Review comments++ 2016-12-01 16:29:35 +05:30
Ilkka Seppälä
efc2c887e9 Merge pull request #521 from Amarnath510/master
Issue #450. First commit. Queue Based Load Leveling
2016-11-28 19:04:31 +02:00
Chandana Amarnath
1d6d0c54a7 pom.xml Fixed Conflict 2016-11-28 20:33:45 +05:30
Chandana Amarnath
1387e2bc96 Fixed all the code changes after review 2016-11-28 20:13:18 +05:30
Ilkka Seppälä
faa29f8025 Update license headers 2016-11-27 14:34:20 +02:00
Ilkka Seppälä
89e7f51e99 Merge pull request #519 from iluwatar/presentation
Add hexagonal architecture presentation
2016-11-27 13:50:04 +02:00
Ilkka Seppälä
cc02ff472b Merge pull request #503 from igeligel/master
Object Mother pattern #498
2016-11-26 20:22:48 +02:00
NooBxGockeL
7d995056ff Update URM Version to 1.4.4 and regenerated all puml files 2016-11-26 12:51:06 +01:00
Ilkka Seppälä
8574e06966 Proxy pattern: Add missing license header 2016-11-23 22:08:50 +02:00
Ilkka Seppälä
82d3d7bf1f Proxy pattern: Improve the example 2016-11-23 22:03:26 +02:00
Chandana Amarnath
1a75ab8df1 Removed unused imports in tests 2016-11-23 09:00:04 +05:30
Ilkka Seppälä
92f8501f7d Decorator pattern: Improve the example 2016-11-22 23:08:39 +02:00
Chandana Amarnath
b9ac0dc6a3 Fixed PMD issue. 2016-11-23 00:10:30 +05:30
Amarnath Chandana
5e7887d9be Reverted pom.xml changes that are done previously. 2016-11-22 12:21:24 +05:30
Amarnath Chandana
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
Chandana Amarnath
d6b5456f98 Updated checkstyle errors. 2016-11-20 23:36:23 +05:30
Chandana Amarnath
52a81eb368 Issue #450. Updated pom.xml 2016-11-20 21:55:56 +05:30
Chandana Amarnath
12b70cb39c Issue #450. First commit. Queue Based Load Leveling 2016-11-20 16:25:10 +05:30
Ilkka Seppälä
68ec24c62e Merge pull request #515 from dbryla/master
#502 Added logging framework to repository
2016-11-18 20:47:17 +02:00
daniel-bryla
3091ff21b0 #502 Reduced amount of information logged 2016-11-17 09:54:10 +01:00
Ilkka Seppälä
95b651f177 Merge pull request #520 from thomasoss/patch-1
Update App.java
2016-11-15 21:31:34 +02:00
Amit Dixit
f67d2fd9a9 Review comments++ 2016-11-15 13:01:37 +05:30
Amit Dixit
4ff8fa3721 Review comments++ 2016-11-15 12:59:05 +05:30
Thomas
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
Ilkka Seppälä
1abf5b11c3 Add presentation link to README.md 2016-11-13 11:37:49 +02:00
Ilkka Seppälä
22d973c460 Merge branch 'master' into presentation 2016-11-13 11:34:14 +02:00
Ilkka Seppälä
c850295aab Add new diagram 2016-11-13 11:23:22 +02:00
Ilkka Seppälä
4c24d99414 Work on Hexagonal Architecture presentation 2016-11-12 22:44:08 +02:00
Ilkka Seppälä
e1ae1067db Link Hexagonal Architecture pattern to corresponding blog entry 2016-11-06 12:26:03 +02:00
Ilkka Seppälä
6f3e2985a4 Create presentation template 2016-11-06 12:14:39 +02:00
daniel-bryla
b37190a214 #502 Introduced logging in new example 2016-11-04 12:19:32 +01:00
daniel-bryla
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
daniel-bryla
e138163c4f #502 Adjusted tests for logger introduction 2016-11-04 11:47:06 +01:00
Ilkka Seppälä
124fd33da0 Remove use of coveralls-maven-plugin (sonarqube.com covers this) 2016-11-01 21:31:54 +02:00
Ilkka Seppälä
9433c78d29 Merge pull request #510 from bellingard/patch-1
Add SonarQube.com badge
2016-10-28 20:39:55 +03:00
Ilkka Seppälä
932700d9b1 Merge pull request #506 from dzmitryh/master
Cosmetic fixes in async-method-invocation
2016-10-28 19:13:17 +03:00
daniel-bryla
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
Amit Dixit
ea7752c5e1 checkstyle errors removed
checkstyle errors removed
2016-10-27 18:30:07 +05:30
Amit Dixit
7ba6cb43fd App
App
2016-10-27 16:00:01 +05:30
Amit Dixit
1ace4c05d6 App++
App++
2016-10-27 15:59:51 +05:30
Amit Dixit
7015e95ac3 SecondCut++
SecondCut++
2016-10-27 15:55:08 +05:30
Amit Dixit
2a77ac29e9 FirstCut++
FirstCut++
2016-10-26 16:59:36 +05:30
igeligel
6aed26e61e Fix pom.xml
Deleted </modules> tag because i added it one time more than neccessary
2016-10-24 15:43:52 +02:00
igeligel
74ac79b01e Fix pom.xml 2016-10-24 15:33:25 +02:00
igeligel
750fa4f954 Merge Changes of the master repository 2016-10-24 15:32:32 +02:00
igeligel
20295316c2 add entry to parent pom.xml #498 2016-10-24 15:30:17 +02:00
igeligel
56b0884258 Change name of variables in test #498 2016-10-24 15:28:27 +02:00
daniel-bryla
0438811489 #502 Replaced usages of System.out with logger. 2016-10-23 19:59:03 +02:00
Fabrice Bellingard
1c02785927 Add SonarQube.com badge 2016-10-23 14:35:45 +02:00
Ilkka Seppälä
19cb715d20 Fix environment variable 2016-10-19 23:08:51 +03:00
Ilkka Seppälä
ffdaf2ec47 Add Travis instructions for SonarQube.com analysis 2016-10-19 22:25:37 +03:00
Ilkka Seppälä
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
Dmitry Avershin
b66e8ecef9 Adds more criticism to Singleton pattern. 2016-10-18 14:18:47 +02:00
Ilkka Seppälä
99677867c6 Event Based Asynchronous pattern: Add missing license header and puml diagram 2016-10-18 07:51:37 +03:00
Ilkka Seppälä
0f7b44c3b1 Merge pull request #483 from waisuan/master
Issue #469: Event-based Asynchronous pattern
2016-10-18 07:43:01 +03:00
WSSIA
70318123fe Changed config to non-interactive 2016-10-17 22:22:06 +01:00
WSSIA
986c529eb6 Moved config into a separate dir 2016-10-17 21:29:03 +01:00
Ilkka Seppälä
64bdab46b9 Merge pull request #495 from christofferh/feat/cache-aside
Caching pattern: Cache-Aside
2016-10-17 22:49:16 +03:00
dzmitryh
37b930c3b7 Unused import removed. 2016-10-15 14:29:32 +03:00
dzmitryh
85060784a7 End process logic clause has been corrected. 2016-10-15 14:27:15 +03:00
Christoffer Hamberg
f114b5b957 Caching pattern: Documentation and diagram 2016-10-09 12:43:43 +02:00
igeligel
863ea75381 Add PlantUML file for the UML diagram #498 2016-10-06 20:12:43 +02:00
igeligel
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
Dmitry Avershin
eea8785a22 Fixes #437. Adds criticism to Singleton pattern. 2016-10-04 14:34:01 +02:00
WSSIA
8f1758c28f Alter JUnit tests to run in lesser time. 2016-10-03 21:46:16 +01:00
WSSIA
622376e0fa Updated version snapshot to 1.14.0 2016-10-03 21:16:23 +01:00
WSSIA
5eacf522a2 Merge remote-tracking branch 'upstream/master' 2016-10-03 21:05:31 +01:00
WSSIA
12544caa75 Changes based on review feedback. 2016-10-03 21:05:11 +01:00
Dmitry Avershin
9512f3ec70 Closes #436. Adds criticism to service locator pattern. 2016-10-03 21:59:36 +02:00
Ilkka Seppälä
4ca205c03c Set version number for next development iteration 2016-09-30 19:40:28 +03:00
Ilkka Seppälä
c5e6dcc11b Reached milestone 1.13.0 2016-09-30 19:38:28 +03:00
Christoffer Hamberg
b31edda3cf Caching pattern: Implementation of Cache-Aside pattern 2016-09-22 20:41:26 +02:00
Christoffer Hamberg
e3355d76d1 Caching pattern: Style fix for null check 2016-09-22 20:36:02 +02:00
Christoffer Hamberg
865f788612 Caching pattern: Refactor LRU cache to avoid NPE and unnecessary cache lookup 2016-09-22 20:35:44 +02:00
Christoffer Hamberg
6ed842e58b Caching pattern: Refactor shutdown hook to use method reference 2016-09-22 20:34:46 +02:00
WSSIA
69cab15d75 Merge remote-tracking branch 'upstream/master' 2016-09-19 21:50:54 +01:00
WSSIA
371b262a51 Changes based on latest code review 2016-09-19 21:50:23 +01:00
WSSIA
dbd605e378 Changes based on latest code review 2016-09-19 21:50:04 +01:00
Ilkka Seppälä
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
Ilkka Seppälä
b030cd4eba Hexagonal pattern: Introduce lottery utils class 2016-09-17 09:20:33 +03:00
Ilkka Seppälä
6aa58e8ae6 Hexagonal pattern: Remove unnecessary factories 2016-09-17 09:07:06 +03:00
Ilkka Seppälä
914d1353a1 Hexagonal pattern: Update test application description 2016-09-15 21:56:15 +03:00
Ilkka Seppälä
df32a7b893 Hexagonal pattern: Introduced lottery events port with two adapters 2016-09-15 21:45:09 +03:00
Ilkka Seppälä
c4c5e78e50 Hexagonal pattern: Improve error handling in console lottery 2016-09-14 22:18:42 +03:00
Ilkka Seppälä
3cf2b34d2a Hexagonal pattern: Improve connection properties handling 2016-09-14 22:01:41 +03:00
Ilkka Seppälä
27e8cb7f2d Hexagonal pattern: Add separate class for Mongo connection properties 2016-09-14 19:25:26 +03:00
Ilkka Seppälä
e685512ed5 Hexagonal pattern: Added Mongo based banking adapter and bound it in Guice production module 2016-09-11 23:19:02 +03:00
WSSIA
f2159515bc Merge remote-tracking branch 'upstream/master' 2016-09-11 20:33:51 +01:00
Ilkka Seppälä
59e6a0af85 Hexagonal pattern: Ignore Mongo repository test 2016-09-11 22:16:50 +03:00
WSSIA
9a90f2de1f Changes based on code review 2016-09-11 18:45:51 +01:00
Ilkka Seppälä
626c56730c Hexagonal pattern: Added Mongo based ticket repository and set production configuration to use that 2016-09-11 20:02:34 +03:00
WSSIA
fce30db803 Updating fork branch 2016-09-11 16:24:16 +01:00
Ilkka Seppälä
a85463470e Hexagonal pattern: Add mongo driver dependency 2016-09-11 13:53:00 +03:00
Ilkka Seppälä
4410419914 Hexagonal pattern: Simplified lottery ticket ids 2016-09-11 10:34:12 +03:00
Ilkka Seppälä
e17d72bca8 Hexagonal pattern: Added console interfaces for players and administration. 2016-09-10 14:28:05 +03:00
Ilkka Seppälä
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
Ilkka Seppälä
adc6019c7e Hexagonal pattern: Remove interfaces with only one implementation 2016-09-10 07:14:24 +03:00
Ilkka Seppälä
0f2807b9cf Hexagonal pattern: More descriptive class names 2016-09-09 21:36:17 +03:00
Ilkka Seppälä
1b10ddbb73 Hexagonal pattern: Use Guice dependency injection 2016-09-06 22:39:39 +03:00
Ilkka Seppälä
348e577e8e Hexagonal pattern: Add Guice dependency 2016-09-06 21:39:08 +03:00
Ilkka Seppälä
22821ba8cc Move Guice to parent pom dependency management section 2016-09-06 21:35:36 +03:00
Markus Moser
4493341ba6 add documentation to 'use latest java 8' change 2016-09-04 11:00:24 +02:00
Ilkka Seppälä
3cb872807e Hexagonal pattern: remove unnecessary repository usage from a unit test 2016-09-04 10:33:26 +03:00
Ilkka Seppälä
ab68129829 Hexagonal pattern: move business logic to core 2016-09-03 22:02:08 +03:00
Ilkka Seppälä
e57a0948ef Merge pull request #490 from iluwatar/DocumentUsages
#211 Document GoF usages from Java API
2016-09-03 14:14:13 +03:00
WSSIA
233f1e69f9 Removed PUBLIC modifiers from IEvent 2016-09-03 11:32:31 +01:00
WSSIA
f11597136f Fixed Checkstyle errors. 2016-09-03 11:32:29 +01:00
WSSIA
e1836fee2f Updated parent POM to include new pattern (Event-asynchronous) 2016-09-03 11:32:28 +01:00
WSSIA
2d99061902 Issue #469: Implementation of Event-based Asynchronous pattern 2016-09-03 11:32:25 +01:00
Ilkka Seppälä
ff23e90c4f Add puml for Promise pattern 2016-09-03 08:43:35 +03:00
Markus Moser
fa52a7f77e Run build with latest java 8 release 2016-09-03 00:19:50 +02:00
Markus Moser
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
NooBxGockeL
be2c7fdb2b Update URM version: 1.4.0 -> 1.4.1, fixes #492 2016-09-02 23:15:38 +02:00
Ilkka Seppälä
90c636abd3 Add missing license headers 2016-09-02 21:28:45 +03:00
Ilkka Seppälä
678a06e7f8 Merge pull request #470 from iluwatar/Promise
Implements #403 Promise pattern
2016-09-02 20:47:21 +03:00
Markus Moser
e425c2ef2f Add webhook for travis build failures to gitter
Only the core group (private) gitter room
2016-08-31 13:15:44 +02:00
Narendra Pathai
5c1a4f1caf Added example that mocking frameworks use proxy pattern 2016-08-31 16:12:13 +05:30
NooBxGockeL
58dce1bd89 Work on #190: Commit initial pumlId's added by the script 2016-08-30 15:10:34 +02:00
NooBxGockeL
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
Markus Moser
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
NooBxGockeL
36fe249960 Work on #190: Add first batch of automagically generated puml files 2016-08-30 13:29:12 +02:00
NooBxGockeL
e73867f9a1 Work on #190: Add automagic puml generation in pom.xml's 2016-08-30 13:24:53 +02:00
Narendra Pathai
59cf100302 #403, updated javadocs 2016-08-29 12:04:24 +05:30
Narendra Pathai
ad11ea46b1 Work on #403, javadocs updated 2016-08-29 11:55:30 +05:30
Narendra Pathai
5796e1967f Work on #403, updated diagram and finishing touches 2016-08-29 11:50:33 +05:30
Narendra Pathai
483c61a82a Some refactoring, added javadocs 2016-08-29 00:16:36 +05:30
Narendra Pathai
6575b3ae99 Merge pull request #491 from alexsomai/patch-1
Minor code changes
2016-08-29 00:00:44 +05:30
Alexandru Somai
095adda7e9 Change access level to private 2016-08-26 12:54:20 +03:00
Alexandru Somai
f16ae08bdf Remove extra space 2016-08-26 12:46:30 +03:00
Narendra Pathai
95cf9fe367 Work on #403, made example readable and moved methods into utility 2016-08-22 18:43:29 +05:30
Narendra Pathai
28647cdf48 #211, consistent use of real world examples section in all readme files. 2016-08-20 20:57:48 +05:30
Narendra Pathai
fdcf546112 Merge branch 'master' of https://github.com/iluwatar/java-design-patterns into DocumentUsages 2016-08-20 20:50:30 +05:30
Narendra Pathai
a0c77c32b5 #211 added further examples for structural and behavioral patterns 2016-08-20 20:49:28 +05:30
Narendra Pathai
eb75773891 Added FAQ on Memento pattern
Difference between java Serialization and Memento pattern added
2016-08-20 19:44:48 +05:30
Narendra Pathai
c79df708b1 #211 added real world examples from Java api for creational patterns 2016-08-20 13:17:53 +05:30
Markus Moser
56100927a9 Addendum #481
Change page-index for faq.md
2016-08-15 12:33:24 +02:00
Markus Moser
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
Ilkka Seppälä
b16d7fc970 Configure Travis notification email 2016-08-14 23:00:27 +03:00
Ilkka Seppälä
0b36a3153d Fix checkstyle error 2016-08-14 22:42:59 +03:00
Ilkka Seppälä
7c2f5da926 Add final keyword 2016-08-13 18:28:53 +03:00
Ilkka Seppälä
ffbc5f2f29 Reorganize LotteryNumbers for easier inclusion in the blog 2016-08-13 17:08:57 +03:00
Ilkka Seppälä
d50139e13e Merge pull request #478 from iluwatar/DocumentDoubleCheckIdiom
Documented singleton double check idiom
2016-08-05 18:45:00 +03:00
Narendra Pathai
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
Narendra Pathai
76970633b8 Work on #403, incorporate review changes 2016-08-04 18:10:50 +05:30
Narendra Pathai
55028a49dc Merge pull request #476 from sumityadav6541/master
removed extra "is" from javadoc comments
2016-08-04 17:47:37 +05:30
Sumit Yadav
94c3a2caf3 removed extra "is" from the javadoc of InitializingOnDemandHolderIdiom class 2016-08-03 15:02:46 +05:30
Sumit Yadav
547d798528 Merge pull request #1 from iluwatar/master
merging changes into fork from origin
2016-08-03 14:57:07 +05:30
Narendra Pathai
e7be94d2e4 Merge branch 'Promise' of https://github.com/iluwatar/java-design-patterns into Promise 2016-07-29 13:12:33 +05:30
Narendra Pathai
383e4a3a0b Merge branch 'master' of https://github.com/iluwatar/java-design-patterns into Promise 2016-07-29 13:01:51 +05:30
Ilkka Seppälä
3001fa4a30 Merge pull request #471 from Crossy147/issue-#459
#459 added known alias for monostate pattern
2016-07-27 15:46:17 +03:00
Kamil Pietruszka
5fcef89384 #459 added known aliast for monostate pattern 2016-07-26 20:33:43 +02:00
Narendra Pathai
40ac552542 Work on #403, added README 2016-07-24 01:45:49 +05:30
Narendra Pathai
09ba5ca656 Work on #403, added class diagrams and javadocs 2016-07-22 18:34:05 +05:30
Narendra Pathai
eb560f5f54 Work on #403, removed checkstyle violations 2016-07-22 16:53:01 +05:30
Narendra Pathai
2b945ca27f Work on #403, removed dependency on async method invocation module, added more tests 2016-07-22 16:47:52 +05:30
Narendra Pathai
4bd1f14cfb Merge branch 'master' of https://github.com/iluwatar/java-design-patterns into Promise 2016-07-22 12:52:54 +05:30
Ilkka Seppälä
bc94d0fc26 Fix link 2016-07-21 20:21:36 +03:00
Narendra Pathai
102341443d Work on #403, added application class and test cases. 2016-07-21 19:13:42 +05:30
Ilkka Seppälä
8124fd0771 Adjust pattern categories and tags 2016-07-21 09:27:48 +03:00
Narendra Pathai
ea7503414e Work on #403, added basic implementation of promise pattern 2016-07-20 19:58:20 +05:30
Ilkka Seppälä
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
Przemek Nowak
f7b7f15ec8 #463 Added javax.servlet.Filter to real world examples of intercepting filter 2016-07-17 21:24:12 +02:00
Przemek Nowak
0fbbd8dc81 #463 Added javax.servlet.Filter to real world examples of chain 2016-07-17 16:05:07 +02:00
Ilkka Seppälä
9f0320aeaf Add some tags to Page Object 2016-07-13 00:02:20 +03:00
Ilkka Seppälä
fe1d760c7f Fix license headers 2016-07-12 19:52:56 +03:00
Ilkka Seppälä
b46d2deeb0 Merge pull request #434 from colinbut/master
#229 Page Object Pattern
2016-07-12 19:47:48 +03:00
Colin But
f182e87ee1 fixed app launch 2016-07-10 20:51:52 +01:00
Colin But
85f432fb54 exclude library class from jacoco code coverage 2016-07-09 22:24:17 +01:00
Colin But
7be98fa829 added missing licence headers to 2 files 2016-07-09 22:20:13 +01:00
Ilkka Seppälä
ff8037ee0b Add aliases for Specification pattern 2016-07-07 08:46:56 +03:00
Ilkka Seppälä
849df50394 Fix formatting 2016-07-04 22:22:37 +03:00
Ilkka Seppälä
f806c5b712 Add known uses to Factory Method 2016-07-04 21:52:39 +03:00
Colin But
ef2ada4fdf syncing fork 2016-07-03 21:47:07 +01:00
Colin But
5d58a1b333 syncing fork 2016-07-03 21:46:38 +01:00
Colin But
4a069ee93a new class diagrams 2016-07-03 21:36:03 +01:00
Colin But
88321890c7 remove old class diagram 2016-07-03 21:12:48 +01:00
Colin But
b1e40d9c92 Feedback changes - final and refactored code 2016-07-03 21:12:09 +01:00
Ilkka Seppälä
5c26f46174 Set version number for next development iteration 2016-06-30 18:15:26 +03:00
Ilkka Seppälä
7a118e4209 Reached milestone 1.12.0 2016-06-30 18:14:41 +03:00
Colin But
4eac37c6b5 Feedback changes - removed file 2016-06-28 22:04:39 +01:00
Colin But
c212ee5cb1 Feedback changes - fix dependency in pom 2016-06-28 22:03:57 +01:00
Colin But
8efaf44170 Feedback changes - sort out dependency 2016-06-28 22:02:03 +01:00
Colin But
27e4e9afee Feedback changes - restructed project structure 2016-06-28 21:53:55 +01:00
Colin But
35c0942803 syncing fork 2016-06-27 20:54:45 +01:00
Ilkka Seppälä
e7bd3cade2 Update link for Naked Objects paper 2016-06-26 20:23:05 +03:00
Ilkka Seppälä
f2e1982264 Merge pull request #435 from protopapa/aggregator-microservices
implementation of microservices architectural pattern #296
2016-06-26 17:32:42 +03:00
protopapa
27bbbd8335 fix bug 2016-06-26 14:57:27 +02:00
protopapa
6677d1091d implementation of microservices architectural pattern #296 2016-06-23 22:54:44 +02:00
Colin But
0282d6663f README 2016-06-18 21:08:15 +01:00
Colin But
c8f04d2f0d added Class Diagram 2016-06-18 19:20:29 +01:00
Colin But
53fc8b749a Page Object pattern implementation 2016-06-18 15:40:03 +01:00
Ilkka Seppälä
f57b94ab47 Merge pull request #433 from qza/master
Abstract Document
2016-06-07 22:32:00 +03:00
Ilkka Seppälä
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
VarunVats9
509de9782d renamed HeroBuilder to Builder 2016-05-29 20:05:54 +05:30
Ilkka Seppälä
f6649a4fed Markdown fix 2016-05-22 09:33:50 +03:00
Ilkka Seppälä
9de2cbe73e Merge pull request #421 from iluwatar/hexagonal
Implements #86 Hexagonal Architecture
2016-05-21 22:19:16 +03:00
Ilkka Seppälä
75ed1b1a96 Review fixes 2016-05-21 21:48:25 +03:00
Ilkka Seppälä
2ed3748c9b Improve Singleton holder example 2016-05-07 11:38:55 +03:00
Ilkka Seppälä
0ad9937881 Merge pull request #427 from surgeforward/297
#297 Create API Gateway pattern
2016-05-06 10:14:31 +03:00
tmcconville
f234a6875c #297 Update class diagram to reflect new location of files 2016-05-03 17:41:37 -05:00
tmcconville
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
tmcconville
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
tmcconville
a6036e5787 #297 Update category and tags in README 2016-05-03 16:29:20 -05:00
tmcconville
5abd20f9e1 #297 Update license headers 2016-05-03 16:28:20 -05:00
tmcconville
b115c61873 #297 Fix error in README 2016-04-24 16:05:38 -05:00
tmcconville
b92318ae36 #297 Increase version number 2016-04-24 16:00:53 -05:00
tmcconville
28d259a55c #297 Create README.md 2016-04-24 16:00:39 -05:00
tmcconville
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
tmcconville
a54cea777f #297 Create class diagrams for API Gateway, Price microservice, and Image microservice 2016-04-24 15:24:33 -05:00
Markus Moser
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
Markus Moser
bf7b682549 Add License Shield 2016-04-24 12:25:05 +02:00
Ilkka Seppälä
5b72510c1c Merge pull request #417 from inbravo/master
Data Mapper #34
2016-04-24 00:02:48 +03:00
Ilkka Seppälä
49ca63087c Merge branch 'master' into hexagonal
# Conflicts:
#	pom.xml
2016-04-20 22:32:22 +03:00
Amit Dixit
af1db79aa7 version++ 2016-04-20 07:23:12 +05:30
Amit Dixit
59e9d027d4 version++ 2016-04-19 12:45:12 +05:30
Amit Dixit
018a4e52a2 build error fix++ 2016-04-19 12:23:52 +05:30
Amit Dixit
93b0b3730e build error fix++ 2016-04-19 11:59:27 +05:30
Amit Dixit
d5f7cb4e2c build check style error-- 2016-04-19 11:49:35 +05:30
Amit Dixit
8fa774d420 mvn build file++ 2016-04-19 11:35:13 +05:30
Amit Dixit
28c2714862 review comments++
review comments++
2016-04-19 11:25:42 +05:30
Ilkka Seppälä
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
Amit Dixit
32736fc90c uml diagram++ 2016-04-18 17:05:18 +05:30
Amit Dixit
8529d6e34b First review changes++
First review changes++
2016-04-18 13:14:20 +05:30
gwildor28
a2843297d8 JUnit tests 2016-04-17 14:46:52 +01:00
Ilkka Seppälä
886ad7e8f0 Fix some markdown errors 2016-04-16 08:52:16 +03:00
Ilkka Seppälä
6f89315aa9 Fix minor display error on web site 2016-04-15 08:41:15 +03:00
Ilkka Seppälä
cf0570a5ed Fix display error 2016-04-15 08:38:08 +03:00
Ilkka Seppälä
8e69ebce9f Fix display error 2016-04-15 08:21:29 +03:00
Ilkka Seppälä
439e286f00 Fix minor display error 2016-04-15 08:13:51 +03:00
gwildor28
e821abdb1b updated version to fix pom 2016-04-14 17:44:18 +01:00
gwildor28
685d093cff added relative paths to pom in mutex/semaphore 2016-04-14 17:33:52 +01:00
gwildor28
ca8be7c43e pom update 2016-04-13 19:26:31 +01:00
gwildor28
3f9a756657 pom update 2016-04-13 19:25:02 +01:00
gwildor28
1fd15d535b Merge remote-tracking branch 'refs/remotes/iluwatar/master' 2016-04-13 18:51:55 +01:00
Ilkka Seppälä
b72214da2f Fix H2 database path problem 2016-04-12 23:04:37 +03:00
Ilkka Seppälä
a7dfe7681e Add alias names 2016-04-11 23:17:27 +03:00
Ilkka Seppälä
cfda338617 Fix version number 2016-04-10 22:03:24 +03:00
Ilkka Seppälä
e546d5dacc Add general description for the example code 2016-04-10 21:50:02 +03:00
Ilkka Seppälä
c2f4194c07 Add alias name for the pattern 2016-04-10 21:49:40 +03:00
Ilkka Seppälä
ccc1ec921a Add readme and class diagram 2016-04-10 21:22:40 +03:00
Ilkka Seppälä
9b3aa785ed Add missing license headers 2016-04-09 17:21:27 +03:00
Ilkka Seppälä
0fe8eec610 Fix merge conflict 2016-04-09 17:17:29 +03:00
Ilkka Seppälä
68725bf3cc Merge branch 'master' into hexagonal 2016-04-09 17:16:07 +03:00
Ilkka Seppälä
5de9c7e6b4 Lots of improvements to the example 2016-04-09 16:53:34 +03:00
Ilkka Seppälä
48803d4c7d Add example lottery run 2016-04-09 16:01:47 +03:00
Ilkka Seppälä
b94a705161 Add constants for win sum and prize payer's bank account 2016-04-09 15:14:12 +03:00
Ilkka Seppälä
335737d7dd Add alias for Multiton 2016-04-06 20:37:02 +03:00
Amit Dixit
06e0a15400 Applicability++ 2016-04-06 13:18:42 +05:30
Amit Dixit
c53dcf1274 Intent++ 2016-04-06 13:14:10 +05:30
Amit Dixit
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
Amit Dixit
59b6b817f4 Test/Doc added
Test/Doc added
2016-04-04 15:31:43 +05:30
Amit Dixit
eb72493f13 JDBC removed... 2016-04-04 12:33:43 +05:30
Amit Dixit
deb15e2733 JDBC removed... 2016-04-04 12:24:15 +05:30
Markus Moser
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
tmcconville
4ebb64c092 #297 Create unit test for PriceController 2016-04-02 18:33:50 -05:00
tmcconville
e80583fad7 #297 Create unit test for ImageController 2016-04-02 18:31:58 -05:00
tmcconville
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
tmcconville
01737bc643 #297 Create Spring Boot-backed Price microservice with an endpoint to retrieve a price 2016-04-02 18:19:42 -05:00
tmcconville
0c6d3f2c3a #297 Create Spring Boot-backed Image microservice with an endpoint to retrieve an image path 2016-04-02 18:19:21 -05:00
Ilkka Seppälä
398eb11b11 Set version for the next development iteration 2016-04-02 19:55:04 +03:00
Ilkka Seppälä
1f27dbbf5b Set version for milestone 1.11.0 2016-04-02 19:51:03 +03:00
gwildor28
187658cce9 Merge remote-tracking branch 'iluwatar/master' 2016-03-29 14:19:01 +01:00
gwildor28
e2af78f417 Update According to Review Comments #397
Resubmit of updates
2016-03-29 13:42:54 +01:00
gwildor28
474f2658ee Merge remote-tracking branch 'refs/remotes/iluwatar/master' 2016-03-29 13:36:56 +01:00
Amit Dixit
28a5a43a47 basic implementation ++
basic implementation ++
2016-03-29 16:36:00 +05:30
Ilkka Seppälä
d20145c05d Merge pull request #407 from iluwatar/refactor-dao
Solves #404 Refactor dao
2016-03-28 19:44:07 +03:00
Narendra Pathai
464ae1690b Updated pom 2016-03-28 11:59:29 +05:30
Narendra Pathai
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
Narendra Pathai
f32a3892a3 Merge branch 'master' of https://github.com/iluwatar/java-design-patterns into refactor-dao 2016-03-28 11:06:25 +05:30
Ilkka Seppälä
6608a8de38 Utilize notifications and banking 2016-03-27 23:35:51 +03:00
Ilkka Seppälä
28d3cb2aa2 Add notifications implementation 2016-03-26 22:01:31 +02:00
Ilkka Seppälä
11c0654103 Add banking implementation 2016-03-26 21:47:25 +02:00
Ilkka Seppälä
f620123cee Organize packages 2016-03-26 21:22:49 +02:00
Ilkka Seppälä
d406f0f9c6 Merge pull request #412 from slawiko/patch-1
Override annotation added
2016-03-26 21:03:34 +02:00
Ilkka Seppälä
ac468bb7e7 Added high level lottery test 2016-03-26 15:54:40 +02:00
Slava Shchaurouski
0c56d800c5 Override annotation added
I think this is a typo
2016-03-26 15:22:33 +03:00
Ilkka Seppälä
4bb7ddaec1 Work on admin tests 2016-03-26 12:42:23 +02:00
Ilkka Seppälä
39a1c1e956 Implement admin interface 2016-03-26 12:28:51 +02:00
Ilkka Seppälä
656b599687 Refactor to test utils 2016-03-26 12:28:31 +02:00
Narendra Pathai
9074a9ca05 Merge branch 'saifulazad-patch-1' 2016-03-26 15:54:38 +05:30
Narendra Pathai
b14aff17b6 Updated failing test cases 2016-03-26 15:54:10 +05:30
Narendra Pathai
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
Ilkka Seppälä
100a72a5e2 Merge pull request #402 from iluwatar/mute-idiom
Implements Mute idiom
2016-03-26 11:07:46 +02:00
Ilkka Seppälä
8d6bc522cd Simplify lottery ticket submit 2016-03-26 11:03:40 +02:00
Narendra Pathai
a395316a80 Added readme 2016-03-26 13:54:03 +05:30
Narendra Pathai
80875a9ac8 Removed dependency on Mockito from pom 2016-03-26 12:36:50 +05:30
Narendra Pathai
4d820b12ff Changes after review. Added README 2016-03-26 12:33:02 +05:30
Narendra Pathai
e543ee0a9c Merge branch 'master' of https://github.com/iluwatar/java-design-patterns into mute-idiom 2016-03-26 12:11:09 +05:30
Ilkka Seppälä
2f5a2be27a Fix missing table error 2016-03-25 22:00:08 +02:00
Saiful Islam
e549af25dd Severe is not appropriate.
"Sever" is most Appropriate
2016-03-25 22:50:17 +06:00
gwildor28
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
Narendra Pathai
3f7ead5ca5 Work on #404, updated class diagram and javadoc. Passed checkstyle checks 2016-03-23 13:13:19 +05:30
Ilkka Seppälä
266b658ab5 Refactor interfaces 2016-03-22 22:45:25 +02:00
Ilkka Seppälä
d2f620a5e6 Added tests for lottery ticket repository 2016-03-22 21:27:13 +02:00
Markus Moser
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
Narendra Pathai
fa077c8be9 Work on #404, javadocs and test cases for DB and in memory dao. 2016-03-21 17:55:29 +05:30
Ilkka Seppälä
8b147c4dd9 Add mock database for lottery tickets 2016-03-20 20:56:04 +02:00
Ilkka Seppälä
fde33999b7 Added interface for lottery administrators 2016-03-20 14:38:24 +02:00
Ilkka Seppälä
e8671e1d6e Add interface for lottery event notifications 2016-03-20 14:33:41 +02:00
Ilkka Seppälä
15d2b9dcca Added interface to lottery service provider's bank account 2016-03-20 14:26:43 +02:00
Ilkka Seppälä
95e6a67056 Added interface for accessing lottery tickets in database 2016-03-20 14:09:44 +02:00
Ilkka Seppälä
2785f6915b Add lottery ticket check result 2016-03-20 11:10:06 +02:00
slawiko
bd1b65276e all index.md files renamed to README.md for more compatibility with github 2016-03-20 11:50:21 +03:00
Ilkka Seppälä
804ffc3ea7 Added lottery service interface 2016-03-20 10:49:31 +02:00
Ilkka Seppälä
035b14fef8 Added lottery ticket and unit tests 2016-03-19 21:57:57 +02:00
Ilkka Seppälä
81718eb8ae Added player details and unit tests 2016-03-19 21:08:55 +02:00
Ilkka Seppälä
cd3a5d48d8 Work on lottery numbers unit tests 2016-03-19 20:37:36 +02:00
Ilkka Seppälä
b0f96adeb1 Added class for lottery numbers and unit tests for it 2016-03-19 18:13:30 +02:00
Narendra Pathai
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
Narendra Pathai
f6a20c7693 Refactoring changes to DAO pattern. Renamed default dao implementation to InMemory and refined interface 2016-03-16 18:47:07 +05:30
Narendra Pathai
e5217bbde8 Work on #385, added missing license template 2016-03-16 12:48:53 +05:30
Narendra Pathai
40e5c8d587 Merge branch 'master' of https://github.com/iluwatar/java-design-patterns into mute-idiom 2016-03-16 12:41:15 +05:30
Narendra Pathai
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
Narendra Pathai
7aff77ab27 Used mockito to replicate SQLException while closing connection to show use of loggedMute 2016-03-15 18:44:59 +05:30
Ilkka Seppälä
528d179efe Add missing license headers 2016-03-13 17:29:09 +02:00
Ilkka Seppälä
06546ae3cf Fix license headers 2016-03-13 17:23:31 +02:00
Ilkka Seppälä
2ed089900d Initial commit for Hexagonal Architecture pattern 2016-03-13 17:23:15 +02:00
Ilkka Seppälä
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
Narendra Pathai
414cdfa332 Merge pull request #398 from legka/master
Event driven architecture refactored.
2016-03-09 10:49:08 +05:30
Oleg
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
gwildor28
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
Narendra Pathai
adb94044ff Work on #385, created project and provided two mute methods 2016-03-01 17:28:28 +05:30
Narendra Pathai
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
Ilkka Seppälä
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
Mohammed Ezzat
046e131119 squid:UselessParenthesesCheck - Useless parentheses around expressions should be removed to prevent any misunderstanding 2016-02-23 20:57:55 +02:00
Mohammed Ezzat
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
Mohammed Ezzat
3791a80978 squid:S2325 - private methods that don't access instance data should be static 2016-02-22 19:15:51 +02:00
Ilkka Seppälä
ab19c47415 Merge pull request #388 from Crossy147/monad-pattern
Monad pattern
2016-02-21 20:36:05 +02:00
Ilkka Seppälä
9f086ba72c Merge pull request #382 from Crossy147/master
issue #333 Factory-kit
2016-02-21 19:56:53 +02:00
Crossy147
cfd83b5753 issue #333 review changes 2016-02-21 12:54:40 +01:00
Crossy147
81e8d354a9 issue #335 review changes 2016-02-21 12:10:08 +01:00
Ilkka Seppälä
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
Ilkka Seppälä
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
Ilkka Seppälä
bbd769b208 Merge pull request #386 from amitbhoraniya/master
Dao Pattern : Create object with reference to Interface
2016-02-20 18:34:47 +02:00
Mohammed Ezzat
d3689b2040 squid:S00119 - Type parameter names should comply with a naming convention 2016-02-20 18:19:44 +02:00
Ilkka Seppälä
ea81ef71ab Merge pull request #377 from iluwatar/FactoryMethodChanges
Factory and Abstract Factory changes
2016-02-20 17:49:14 +02:00
Crossy147
80ff7bb217 issue #335 brace typo 2016-02-20 15:01:45 +01:00
Crossy147
64f1fe8979 issue #335 typos fixed 2016-02-20 14:55:37 +01:00
Crossy147
f47b9283c3 Merge branch 'master' of https://github.com/iluwatar/java-design-patterns into monad-pattern 2016-02-19 19:10:43 +01:00
Crossy147
72e08365b8 issue #335 documentation improvements 2016-02-19 19:08:35 +01:00
Crossy147
3e526cb5da issue #335 Monad pattern introduced 2016-02-19 17:56:09 +01:00
Mohammed Ezzat
50310aaeaf squid:S1699 - Constructors should only call non-overridable methods 2016-02-19 11:02:49 +02:00
Amit Bhoraniya
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
Narendra Pathai
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
Mohammed Ezzat
0003c6cb00 pmd:RedundantFieldInitializer - Redundant-Field-Initializer 2016-02-18 08:40:19 +02:00
Crossy147
6ab9b36d59 issue #333 javadocs changes 2016-02-17 19:35:10 +01:00
Crossy147
2fa705ab59 issue #333 snapshot version fixed 2016-02-16 00:05:28 +01:00
Crossy147
8fabc861b3 pom.xml minor 2016-02-15 21:57:26 +01:00
Crossy147
53fdaba6c4 Merge branch 'master' of https://github.com/iluwatar/java-design-patterns 2016-02-15 21:48:07 +01:00
Crossy147
8b625a8d3c issue #333 minor revert 2016-02-15 20:54:55 +01:00
Crossy147
022ab28e20 issue #333 diagrams and index added 2016-02-15 20:37:16 +01:00
Narendra Pathai
f1122f78e3 Added real life application to Command pattern 2016-02-15 18:21:34 +05:30
Narendra Pathai
cd077fa490 Merge branch 'master' of https://github.com/iluwatar/java-design-patterns into FactoryMethodChanges 2016-02-12 15:49:35 +05:30
Narendra Pathai
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
Narendra Pathai
221b71781a Resolved checkstyle audit error 2016-02-11 12:29:35 +05:30
Narendra Pathai
b5d4445d63 Made example App a bit easier to understand 2016-02-10 17:53:32 +05:30
Narendra Pathai
f64ba22c64 1) Removed warning from test case. 2) Made implementation of App more understandable. 2016-02-10 17:38:15 +05:30
Mohammed Ezzat
632174b6dc squid:S2974 - Classes without public constructors should be final 2016-02-09 17:19:31 +02:00
Ilkka Seppälä
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
tmcconville
3cbb88e09c #297 Create unit tests for Gateway API pattern 2016-02-07 17:05:45 -06:00
tmcconville
88c3b04eb3 #297 Create API Gateway pattern 2016-02-07 17:05:33 -06:00
Mohammed Ezzat
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
Ilkka Seppälä
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
Ilkka Seppälä
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
Ilkka Seppälä
9b6517453f Merge pull request #362 from JuhoKang/master
Value object pattern #349
2016-02-05 21:04:21 +02:00
Mohammed Ezzat
df4a40fc13 squid:S1186 - Methods should not be empty 2016-02-03 21:51:40 +02:00
JuhoKang
83533543e6 format code 2016-02-03 23:38:13 +09:00
JuhoKang
f71e186959 Fixed descriptions in code. 2016-02-03 23:33:40 +09:00
JuhoKang
db2140ecc9 updated child and parent pom 2016-02-03 23:02:27 +09:00
JuhoKang
049841298e deleted the change in parent pom 2016-02-03 22:59:15 +09:00
JuhoKang
1e5cbe1f76 Merge remote-tracking branch 'upstream/master' 2016-02-03 22:49:59 +09:00
Jeroen Meulemeester
53cc97e9d0 Update license year from 2014 to range '2014-2016' 2016-02-03 07:15:19 +01:00
Ilkka Seppälä
33224dd7d7 Prepare for next development iteration 2016-02-02 22:14:20 +02:00
Ilkka Seppälä
4f56f7b097 Achieved milestone 1.10.0 2016-02-02 22:11:38 +02:00
Ilkka Seppälä
e25cbad811 Merge pull request #367 from mikulucky/master
Feature Toogle PR
2016-02-02 22:02:15 +02:00
Markus Moser
6caea8557b added missing space, 'cause website didnt display correctly 2016-02-02 17:31:12 +01:00
JuhoKang
d8378915a1 pom.xml change to fit upstream 2016-02-02 08:02:38 +09:00
JuhoKang
0e7fae21c3 Edit pom.xml 2016-02-02 07:48:43 +09:00
JuhoKang
3ef464986c Merge remote-tracking branch 'upstream/master', fixed f-c index properly 2016-02-02 07:35:06 +09:00
Ilkka Seppälä
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
Ilkka Seppälä
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
Joseph McCarthy
c7f4311706 #354 Clean up 2016-02-01 18:57:05 +00:00
Joseph McCarthy
37da470178 #354 Finish Readme 2016-02-01 18:45:54 +00:00
Mohammed Ezzat
7adefc89ba pmd:AppendCharacterWithChar - Append Character With Char 2016-02-01 04:20:52 +02:00
Joseph McCarthy
b27d6dff66 Merge branch 'master' of github.com:mikulucky/java-design-patterns
terns
Update
2016-01-31 23:28:28 +00:00
Joseph McCarthy
bf5ba44260 #354 add App.java 2016-01-31 23:24:35 +00:00
Joseph McCarthy
8603333e5d #354 Adding Class Diagram 2016-01-31 14:10:34 +00:00
Joseph McCarthy
7cc93de672 #354 Merged Remote Master and resolved conflicts 2016-01-31 13:58:00 +00:00
Joseph McCarthy
c2e750aca1 #354 finished method javadocs 2016-01-31 13:46:34 +00:00
Ilkka Seppälä
59c32d3937 Add tests that run the examples 2016-01-31 12:09:09 +02:00
Ilkka Seppälä
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
Ilkka Seppälä
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
Ilkka Seppälä
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
Mohammed Ezzat
409ff027b8 squid:S2293 - The diamond operator should be used 2016-01-29 07:33:34 +02:00
Joseph McCarthy
98326a1e5e #354 Start Adding Java docs 2016-01-28 21:14:40 +00:00
JuhoKang
d3eb8a2ef2 Added comments in the code. modified index.md 2016-01-29 00:53:27 +09:00
JuhoKang
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
JuhoKang
cca40a543a Added Code 2016-01-28 22:39:50 +09:00
Joseph McCarthy
3d95696078 #358 Added license to all files using plugin 2016-01-27 22:20:42 +00:00
Joseph McCarthy
321f5d6c5a Merge branch 'master' of https://github.com/iluwatar/java-design-patterns into MIT-Source 2016-01-27 22:15:15 +00:00
Joseph McCarthy
7b61395bc1 #358 Add Plugin for Auto License 2016-01-27 22:14:28 +00:00
Narendra Pathai
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
Mohammed Ezzat
4e40cc3888 squid:S1488 - Local Variables should not be declared and then immediately returned or thrown 2016-01-27 02:45:39 +02:00
Joseph McCarthy
77e14f0069 #354 Add tests for Properties 2016-01-26 23:38:28 +00:00
Joseph McCarthy
4a49f82f23 #354 add general boolean method to services for feature status. Change user.toString 2016-01-26 21:18:47 +00:00
Joseph McCarthy
ba1d3a0fbf #354 Added Configuration Based Example of Feature Toggle 2016-01-26 21:08:28 +00:00
Joseph McCarthy
d627b7af6b #354 Moved Tests to the correct area 2016-01-26 20:24:43 +00:00
Joseph McCarthy
91b2379fd0 #354 Fixed CheckStyle Issues 2016-01-26 19:20:28 +00:00
Joseph McCarthy
32f9cf3ab1 #354 Some clean up and show the difference between paid and free a bit more. 2016-01-26 18:58:35 +00:00
Joseph McCarthy
a1ede8980f #354 Added WelcomeMessage Service and Tests for tier example of featureToggle 2016-01-26 18:49:25 +00:00
Joseph McCarthy
72733acfc6 #354 added usergroup for version of feature toggle 2016-01-26 18:41:08 +00:00
Mohammed Ezzat
d00bfae5ee pmd:ConsecutiveAppendsShouldReuse - Consecutive Appends Should Reuse 2016-01-26 19:58:45 +02:00
Joseph McCarthy
0b834128b9 #354 Add Blank index.md 2016-01-25 21:29:05 +00:00
Joseph McCarthy
89e0e3e73e #354 Remove generated copyright banner 2016-01-25 21:16:35 +00:00
Joseph McCarthy
d7526fc7c0 #354 Add maven model for feature toggle design pattern 2016-01-25 21:14:24 +00:00
Joseph McCarthy
cf10bd1d05 #354 Add maven model for feature toggle design pattern 2016-01-25 21:11:26 +00:00
Joseph McCarthy
5ad99be224 #354 Add maven model for feature toggle design pattern 2016-01-25 21:10:58 +00:00
JuhoKang
64b89ecb59 Create project for value-object pattern 2016-01-23 10:06:57 +09:00
NooBxGockeL
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
Kamil Pietruszka
10bbf988ea issue #333 factory kit pattern introduced 2016-01-17 13:47:44 +01:00
Ilkka Seppälä
bd82387fc1 Merge pull request #345 from azhuzhu/master
Fix the wrong uml .png name in decorator
2016-01-14 19:47:09 +02:00
Ilkka Seppälä
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
Yuming Zhu
033dce8387 Fix the wrong uml .png name in decorator 2016-01-15 00:56:46 +08:00
hoswey
e95cfe9292 fix issue #343 ReaderWriterLock unit tests fail on CI 2016-01-13 09:35:31 +08:00
Ilkka Seppälä
150c4e0d5d Ignore rest of ReaderWriterLock tests with intermittent failures 2016-01-12 21:16:39 +02:00
Ilkka Seppälä
c8db19efe2 Ignore another test with intermittent failures until fixed 2016-01-12 21:08:10 +02:00
Ilkka Seppälä
2fec4f891b Ignore test with intermittent failures until fixed 2016-01-12 20:57:36 +02:00
Ilkka Seppälä
adf131b784 Merge pull request #326 from hoswey/master
implements the #75 reader writer lock
2016-01-12 20:15:22 +02:00
hoswey
77d45c35e0 implements the #75 reader writer lock, fix the problem of review 2016-01-10 21:23:52 +08:00
hoswey
2f84369003 Merge remote-tracking branch 'upstream/master' 2016-01-09 22:26:18 +08:00
Ilkka Seppälä
83f1ac7489 Update dependencies 2016-01-07 21:41:45 +02:00
Ilkka Seppälä
03e187743c Merge pull request #340 from tomroy/master
Decorator pattern: SmartTroll should be SmartHostile #264
2016-01-06 19:44:26 +02:00
Tom.TH.Lin
bd83fa28bb Correct method name and cleanup etc folder #264 2016-01-07 00:34:33 +08:00
Tom.TH.Lin
30ca1ea1fb Decorator pattern: SmartTroll should be SmartHostile #264 2016-01-04 23:07:33 +08:00
Markus
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
Jeroen Meulemeester
3d642cdad7 Use headings instead of bold text in index.md #238 2016-01-03 21:14:30 +01:00
Ilkka Seppälä
b6beffec2e Merge pull request #299 from genericmethod/master
#113 Event-driven Architecture
2016-01-03 14:50:46 +02:00
Chris Farrugia
1987bdb962 Merge pull request #1 from mikulucky/master
Class Diagram for EDA
2016-01-03 12:20:35 +00:00
Joseph McCarthy
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
Joseph McCarthy
d6719729b9 Revert "Revert "Merge remote-tracking branch 'origin/master'""
This reverts commit 03f0a2112b.
2016-01-03 00:54:49 +00:00
Joseph McCarthy
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
Joseph McCarthy
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
Joseph McCarthy
0c062d3f55 Add class diagram for #113 and to be included in PR #299 2016-01-03 00:01:43 +00:00
Joseph McCarthy
248ea5191a Merge remote-tracking branch 'origin/master' 2016-01-02 23:59:47 +00:00
Joseph McCarthy
39b183d569 Merge pull request #2 from genericmethod/master
Pull
2016-01-02 23:58:43 +00:00
Joseph McCarthy
02bd15db90 Merge remote-tracking branch 'iluwatar/master' 2016-01-02 18:39:58 +00:00
Ilkka Seppälä
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
cfarrugia
7176b86146 #113 Event Driven Architecture
bumped up version to 1.10
2016-01-02 14:05:36 +01:00
cfarrugia
2ea9bfef19 #113 Event Driven Architecture
Fixed PMD errors
2016-01-02 14:04:07 +01:00
cfarrugia
40042ae392 Merge remote-tracking branch 'iluwatar/master'
# Conflicts:
#	pom.xml
2016-01-02 11:48:01 +01:00
Joseph McCarthy
e25ef1b0f8 Check Style fixes #334 2016-01-02 00:54:26 +00:00
Joseph McCarthy
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
Ilkka Seppala
e0e51324db Set version number for next development iteration 2016-01-01 20:39:20 +02:00
hoswey
3731d26f6d implants the #75 reader writer lock 2015-12-26 14:17:24 +08:00
cfarrugia
898f3a428c #113 Event Driven Architecture
Fixed a typo in index.md
2015-12-02 01:43:34 +01:00
cfarrugia
0b46a9985d #113 Event Driven Architecture
Updated index.md with eda uses
2015-12-02 01:39:20 +01:00
cfarrugia
2aa20b7445 #113 Event Driven Architecture
Adds various changes including :
- Fixes to Javadoc
2015-12-01 23:33:26 +01:00
cfarrugia
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
cfarrugia
9e857d7dd6 #113 Event Driven Architecture
Fixed javadoc
2015-11-28 19:05:23 +01:00
cfarrugia
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
cfarrugia
3ad36020aa #113 Event Driven Architecture
Adds unit test to assert and verify pattern behaviour
2015-11-28 17:25:15 +01:00
cfarrugia
e1c0731f7e #113 Event Driven Architecture
Adds more Javadoc and fixes checkstyle issues.
2015-11-28 15:03:22 +01:00
cfarrugia
b8b94b697a #113 Event Driven Architecture
Adds more Javadoc
2015-11-28 13:12:16 +01:00
cfarrugia
fc70a706c6 #113 Event Driven Architecture
Adds module to the root pom.xml
Fixes indentation
2015-11-28 10:57:00 +01:00
chris
321e9d4191 #113 Event Driven Architecture
- added class diagram
- added more comments
2015-11-23 11:20:20 +01:00
chris
b4aeca3aa0 #113 Event Driven Architecture
- removed unused imports
2015-11-23 00:04:44 +01:00
chris
3ef0921f20 #113 Event Driven Architecture
- refactored and moved around some classes
2015-11-23 00:02:58 +01:00
chris
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
1509 changed files with 57845 additions and 6150 deletions

6
.gitignore vendored
View File

@@ -12,3 +12,9 @@ target
*.iml *.iml
*.swp *.swp
datanucleus.log datanucleus.log
/bin/
/bin/
/bin/
*.log
data-mapper/src/main/resources/log4j.xml
event-sourcing/Journal.json

View File

@@ -6,13 +6,34 @@ env:
global: global:
- GH_REF: github.com/iluwatar/java-design-patterns.git - GH_REF: github.com/iluwatar/java-design-patterns.git
- secure: LxTDuNS/rBWIvKkaEqr79ImZAe48mCdoYCF41coxNXgNoippo4GIBArknqtv+XvdkiuRZ1yGyj6pn8GU33c/yn+krddTUkVCwTbVatbalW5jhQjDbHYym/JcxaK9ZS/3JTeGcWrBgiPqHEEDhCf26vPZsXoMSeVCEORVKTp1BSg= - secure: LxTDuNS/rBWIvKkaEqr79ImZAe48mCdoYCF41coxNXgNoippo4GIBArknqtv+XvdkiuRZ1yGyj6pn8GU33c/yn+krddTUkVCwTbVatbalW5jhQjDbHYym/JcxaK9ZS/3JTeGcWrBgiPqHEEDhCf26vPZsXoMSeVCEORVKTp1BSg=
- secure: "eoWlW9GyTJY04P8K3pxayXwU9/hmptQg/LfirispQkV9YvmziCfSzXnatnBhNfud98sCzY8BScXnb+OWLTnjLKpId4rtEqb0aJ40Jc32cUKzgzFAUn7cNcDAbUIfyPAGVqyQqfj/11wYSADwWMMOPlW97ExUtoyiH2WenXuRHso="
before_install: before_install:
- export DISPLAY=:99.0 - export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start - sh -e /etc/init.d/xvfb start
# 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: after_success:
- mvn clean test jacoco:report coveralls:report - mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent package sonar:sonar -Dsonar.host.url=https://sonarqube.com -Dsonar.login=$SONAR_TOKEN
- bash update-ghpages.sh - bash update-ghpages.sh
sudo: false # 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

View File

@@ -1,6 +1,6 @@
The MIT License (MIT) 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 Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal

View File

@@ -5,8 +5,9 @@
# Design patterns implemented 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) [![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) [![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) [![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://sonarqube.com/api/badges/gate?key=com.iluwatar%3Ajava-design-patterns)](https://sonarqube.com/dashboard/index/com.iluwatar%3Ajava-design-patterns)
# Introduction # Introduction
@@ -23,7 +24,7 @@ are familiar with the patterns.
# Getting started # Getting started
Before you dive into the material, you should be familiar with various Before you dive into the material, you should be familiar with various
[Programming/Software Design Principles](http://webpro.github.io/programming-principles/). Programming/Software Design Principles.
All designs should be as simple as possible. You should start with KISS, YAGNI, 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 and Do The Simplest Thing That Could Possibly Work principles. Complexity and
@@ -41,18 +42,6 @@ patterns by any of the following approaches
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). 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).
# Credits
* [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)
# License # License
This project is licensed under the terms of the MIT license. This project is licensed under the terms of the MIT license.

View File

@@ -0,0 +1,67 @@
#
# 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.
#
import requests, glob, re, os
# taken from here: http://stackoverflow.com/a/13641746
def replace(file, pattern, subst):
# Read contents from file as a single string
file_handle = open(file, 'r')
file_string = file_handle.read()
file_handle.close()
# Use RE package to allow for replacement (also allowing for (multiline) REGEX)
file_string = (re.sub(pattern, subst, file_string))
# Write contents to file.
# Using mode 'w' truncates the file.
file_handle = open(file, 'w')
file_handle.write(file_string)
file_handle.close()
# list of all puml files
fileList = glob.glob('*/etc/*.puml')
for puml in fileList:
pathSplit = puml.split("/")
# parent folder
parent = pathSplit[0]
# individual artifact/project name
artifact = pathSplit[2].replace(".urm.puml", "")
print "parent: " + parent + "; artifact: " + artifact
# do a POST to the official plantuml hosting site with a little trick "!includeurl" and raw github content
data = {
'text': "!includeurl https://raw.githubusercontent.com/iluwatar/java-design-patterns/master/" + puml
}
r = requests.post('http://plantuml.com/plantuml/uml', data=data)
pumlId = r.url.replace("http://plantuml.com/plantuml/uml/", "")
# the only thing needed to get a png/svg/ascii from the server back
print "Puml Server ID: " + pumlId
# add the id so jekyll/liquid can use it
if (parent == artifact):
replace("./" + parent + "/README.md", "categories:", "pumlid: {}\\ncategories:".format(pumlId))
else:
print "I dont want to program this, just add the following lines to the README.md file that corresponds to this puml file '" + puml + "'\npumlid: {}".format(pumlId)

View File

@@ -0,0 +1,32 @@
---
layout: pattern
title: Abstract Document
folder: abstract-document
permalink: /patterns/abstract-document/
pumlid: PSjB3eCm34NHhPG599vtDyQn85L-ifzX-p3lxEf8Twj3MXGDQvyJMFubChxpKN767gucSq07iinEjSNDOACVNvoAUZr6MWoe3QVE_WRnxZ0Mf38b-hkIGlurX_MyehS7
categories: Structural
tags:
- Java
- Difficulty-Intermediate
---
## Intent
Achieve flexibility of untyped languages and keep the type-safety
![alt text](./etc/abstract-document-base.png "Abstract Document Base")
![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: 15 KiB

View File

@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="UTF-8"?>
<class-diagram version="1.1.9" icons="true" automaticImage="PNG" 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.abstractdocument.Document" project="design-patterns"
file="/design-patterns/src/com/iluwatar/abstractdocument/Document.java" binary="false" corner="BOTTOM_RIGHT">
<position height="-1" width="-1" x="249" y="405"/>
<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="2" language="java" name="com.iluwatar.abstractdocument.AbstractDocument" project="design-patterns"
file="/design-patterns/src/com/iluwatar/abstractdocument/AbstractDocument.java" binary="false" corner="BOTTOM_RIGHT">
<position height="-1" width="-1" x="250" y="237"/>
<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.abstractdocument.domain.Car" project="design-patterns"
file="/design-patterns/src/com/iluwatar/abstractdocument/domain/Car.java" binary="false" corner="BOTTOM_RIGHT">
<position height="-1" width="-1" x="108" y="75"/>
<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="design-patterns"
file="/design-patterns/src/com/iluwatar/abstractdocument/domain/Part.java" binary="false" corner="BOTTOM_RIGHT">
<position height="-1" width="-1" x="400" y="76"/>
<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="5">
<end type="SOURCE" refId="4"/>
<end type="TARGET" refId="2"/>
</generalization>
<realization id="6">
<end type="SOURCE" refId="2"/>
<end type="TARGET" refId="1"/>
</realization>
<generalization id="7">
<end type="SOURCE" refId="3"/>
<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"/>
<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.

After

Width:  |  Height:  |  Size: 16 KiB

View File

@@ -1,84 +1,92 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<class-diagram version="1.1.8" icons="true" automaticImage="PNG" always-add-relationships="false" generalizations="true" <class-diagram version="1.1.9" icons="true" automaticImage="PNG" always-add-relationships="false" generalizations="true"
realizations="true" associations="true" dependencies="false" nesting-relationships="true"> realizations="true" associations="true" dependencies="false" nesting-relationships="true" router="FAN">
<class id="1" language="java" name="com.iluwatar.facade.DwarvenGoldmineFacade" project="facade" <interface id="1" language="java" name="com.iluwatar.abstractdocument.Document" project="design-patterns"
file="/facade/src/main/java/com/iluwatar/facade/DwarvenGoldmineFacade.java" binary="false" corner="BOTTOM_RIGHT"> file="/design-patterns/src/com/iluwatar/abstractdocument/Document.java" binary="false" corner="BOTTOM_RIGHT">
<position height="160" width="376" x="50" y="263"/> <position height="-1" width="-1" x="341" y="376"/>
<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.abstractdocument.domain.HasModel" project="design-patterns"
file="/design-patterns/src/com/iluwatar/abstractdocument/domain/HasModel.java" binary="false" corner="BOTTOM_RIGHT">
<position height="81" width="173" x="41" y="194"/>
<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="3" language="java" name="com.iluwatar.abstractdocument.domain.HasPrice" project="design-patterns"
file="/design-patterns/src/com/iluwatar/abstractdocument/domain/HasPrice.java" binary="false" corner="BOTTOM_RIGHT">
<position height="81" width="175" x="254" y="194"/>
<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="4" language="java" name="com.iluwatar.abstractdocument.domain.HasParts" project="design-patterns"
file="/design-patterns/src/com/iluwatar/abstractdocument/domain/HasParts.java" binary="false" corner="BOTTOM_RIGHT">
<position height="81" width="173" x="469" y="194"/>
<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="5" language="java" name="com.iluwatar.abstractdocument.domain.Car" project="design-patterns"
file="/design-patterns/src/com/iluwatar/abstractdocument/domain/Car.java" binary="false" corner="BOTTOM_RIGHT">
<position height="99" width="173" x="254" y="37"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true" <display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true"> sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/> <attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/> <operations public="true" package="true" protected="true" private="true" static="true"/>
</display> </display>
</class> </class>
<class id="2" language="java" name="com.iluwatar.facade.DwarvenMineWorker" project="facade" <class id="6" language="java" name="com.iluwatar.abstractdocument.domain.Part" project="design-patterns"
file="/facade/src/main/java/com/iluwatar/facade/DwarvenMineWorker.java" binary="false" corner="BOTTOM_RIGHT"> file="/design-patterns/src/com/iluwatar/abstractdocument/domain/Part.java" binary="false" corner="BOTTOM_RIGHT">
<position height="231" width="171" x="50" y="463"/> <position height="99" width="173" x="41" y="37"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true" <display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true"> sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/> <attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/> <operations public="true" package="true" protected="true" private="true" static="true"/>
</display> </display>
</class> </class>
<class id="3" language="java" name="com.iluwatar.facade.DwarvenCartOperator" project="facade" <realization id="7">
file="/facade/src/main/java/com/iluwatar/facade/DwarvenCartOperator.java" binary="false" corner="BOTTOM_RIGHT"> <end type="SOURCE" refId="5"/>
<position height="124" width="181" x="-272" y="734"/> <end type="TARGET" refId="2"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true" </realization>
sort-features="false" accessors="true" visibility="true"> <realization id="8">
<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.facade.DwarvenGoldDigger" project="facade"
file="/facade/src/main/java/com/iluwatar/facade/DwarvenGoldDigger.java" binary="false" corner="BOTTOM_RIGHT">
<position height="124" width="169" x="-51" y="734"/>
<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>
<enumeration id="5" language="java" name="com.iluwatar.facade.DwarvenMineWorker.Action" project="facade"
file="/facade/src/main/java/com/iluwatar/facade/DwarvenMineWorker.java" binary="false" corner="BOTTOM_RIGHT">
<position height="178" width="164" x="158" y="734"/>
<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="6" language="java" name="com.iluwatar.facade.DwarvenTunnelDigger" project="facade"
file="/facade/src/main/java/com/iluwatar/facade/DwarvenTunnelDigger.java" binary="false" corner="BOTTOM_RIGHT">
<position height="124" width="184" x="362" y="734"/>
<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="7">
<end type="SOURCE" refId="6"/> <end type="SOURCE" refId="6"/>
<end type="TARGET" refId="2"/> <end type="TARGET" refId="2"/>
</generalization> </realization>
<generalization id="8">
<end type="SOURCE" refId="4"/>
<end type="TARGET" refId="2"/>
</generalization>
<generalization id="9"> <generalization id="9">
<end type="SOURCE" refId="3"/>
<end type="TARGET" refId="2"/>
</generalization>
<association id="10">
<end type="SOURCE" refId="1" navigable="false">
<attribute id="11" name="workers"/>
<multiplicity id="12" minimum="0" maximum="2147483647"/>
</end>
<end type="TARGET" refId="2" navigable="true"/>
<display labels="true" multiplicity="true"/>
</association>
<nesting id="13">
<end type="SOURCE" refId="2"/> <end type="SOURCE" refId="2"/>
<end type="TARGET" refId="5"/> <end type="TARGET" refId="1"/>
</nesting> </generalization>
<realization id="10">
<end type="SOURCE" refId="5"/>
<end type="TARGET" refId="3"/>
</realization>
<realization id="11">
<end type="SOURCE" refId="5"/>
<end type="TARGET" refId="4"/>
</realization>
<generalization id="12">
<end type="SOURCE" refId="3"/>
<end type="TARGET" refId="1"/>
</generalization>
<generalization id="13">
<end type="SOURCE" refId="4"/>
<end type="TARGET" refId="1"/>
</generalization>
<realization id="14">
<end type="SOURCE" refId="6"/>
<end type="TARGET" refId="3"/>
</realization>
<classifier-display autosize="true" stereotype="true" package="true" initial-value="false" signature="true" <classifier-display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true"> sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/> <attributes public="true" package="true" protected="true" private="true" static="true"/>

View File

@@ -0,0 +1,59 @@
@startuml
package com.iluwatar.abstractdocument.domain {
class Car {
+ Car(properties : Map<String, Object>)
}
interface HasModel {
+ PROPERTY : String {static}
+ getModel() : Optional<String>
}
interface HasParts {
+ PROPERTY : String {static}
+ getParts() : Stream<Part>
}
interface HasPrice {
+ PROPERTY : String {static}
+ getPrice() : Optional<Number>
}
interface HasType {
+ PROPERTY : String {static}
+ getType() : Optional<String>
}
class Part {
+ Part(properties : Map<String, Object>)
}
}
package com.iluwatar.abstractdocument {
abstract class AbstractDocument {
- properties : Map<String, Object>
# AbstractDocument(properties : Map<String, Object>)
+ children(key : String, constructor : Function<Map<String, Object>, T>) : Stream<T>
+ get(key : String) : Object
+ put(key : String, value : Object)
+ toString() : String
}
class App {
- LOGGER : Logger {static}
+ App()
+ main(args : String[]) {static}
}
interface Document {
+ children(String, Function<Map<String, Object>, T>) : Stream<T> {abstract}
+ get(String) : Object {abstract}
+ put(String, Object) {abstract}
}
}
AbstractDocument ..|> Document
Car ..|> HasModel
Car ..|> HasPrice
Car ..|> HasParts
Car --|> AbstractDocument
HasModel --|> Document
HasParts --|> Document
HasPrice --|> Document
HasType --|> Document
Part ..|> HasType
Part ..|> HasModel
Part ..|> HasPrice
Part --|> AbstractDocument
@enduml

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

@@ -0,0 +1,42 @@
<?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.17.0</version>
</parent>
<artifactId>abstract-document</artifactId>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</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.Test;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Stream;
import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.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.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.Test;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import static junit.framework.TestCase.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());
}
}

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

@@ -0,0 +1,152 @@
---
layout: pattern
title: Abstract Factory
folder: abstract-factory
permalink: /patterns/abstract-factory/
pumlid: PSZB3OD034NHLa81Czwd6sCC39gVxEUWT1_ssLmTtQLqgR5fM7sTmFGtaV6TZu8prd0r6HtQaMKqAZLk1XjT_E6qgPUZfyc0MdTgx0-8LuUn8ErFXdr98NypXxKyezKV
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
```
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
```
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.
```
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!
```
## 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.
## 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

View File

@@ -1,33 +0,0 @@
---
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.
![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)
**Credits**
* [Design Patterns: Elements of Reusable Object-Oriented Software](http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612)

View File

@@ -1,11 +1,35 @@
<?xml version="1.0"?> <?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" <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"> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<parent> <parent>
<groupId>com.iluwatar</groupId> <groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId> <artifactId>java-design-patterns</artifactId>
<version>1.9.0</version> <version>1.17.0</version>
</parent> </parent>
<artifactId>abstract-factory</artifactId> <artifactId>abstract-factory</artifactId>
<dependencies> <dependencies>

View File

@@ -1,5 +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.abstractfactory; package com.iluwatar.abstractfactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** /**
* *
* The Abstract Factory pattern provides a way to encapsulate a group of individual factories that have a common theme * The Abstract Factory pattern provides a way to encapsulate a group of individual factories that have a common theme
@@ -17,6 +42,8 @@ package com.iluwatar.abstractfactory;
*/ */
public class App { public class App {
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
private King king; private King king;
private Castle castle; private Castle castle;
private Army army; private Army army;
@@ -30,14 +57,6 @@ public class App {
setArmy(factory.createArmy()); setArmy(factory.createArmy());
} }
ElfKingdomFactory getElfKingdomFactory() {
return new ElfKingdomFactory();
}
OrcKingdomFactory getOrcKingdomFactory() {
return new OrcKingdomFactory();
}
King getKing(final KingdomFactory factory) { King getKing(final KingdomFactory factory) {
return factory.createKing(); return factory.createKing();
} }
@@ -84,21 +103,17 @@ public class App {
App app = new App(); App app = new App();
System.out.println("Elf Kingdom"); LOGGER.info("Elf Kingdom");
KingdomFactory elfKingdomFactory; app.createKingdom(new ElfKingdomFactory());
elfKingdomFactory = app.getElfKingdomFactory(); LOGGER.info(app.getArmy().getDescription());
app.createKingdom(elfKingdomFactory); LOGGER.info(app.getCastle().getDescription());
System.out.println(app.getArmy().getDescription()); LOGGER.info(app.getKing().getDescription());
System.out.println(app.getCastle().getDescription());
System.out.println(app.getKing().getDescription());
System.out.println("\nOrc Kingdom"); LOGGER.info("Orc Kingdom");
KingdomFactory orcKingdomFactory; app.createKingdom(new OrcKingdomFactory());
orcKingdomFactory = app.getOrcKingdomFactory(); LOGGER.info(app.getArmy().getDescription());
app.createKingdom(orcKingdomFactory); LOGGER.info(app.getCastle().getDescription());
System.out.println(app.getArmy().getDescription()); LOGGER.info(app.getKing().getDescription());
System.out.println(app.getCastle().getDescription());
System.out.println(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; package com.iluwatar.abstractfactory;
/** /**

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; package com.iluwatar.abstractfactory;
/** /**

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; package com.iluwatar.abstractfactory;
/** /**

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; package com.iluwatar.abstractfactory;
/** /**

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; package com.iluwatar.abstractfactory;
/** /**

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; package com.iluwatar.abstractfactory;
/** /**

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; package com.iluwatar.abstractfactory;
/** /**

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; package com.iluwatar.abstractfactory;
/** /**

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; package com.iluwatar.abstractfactory;
/** /**

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; package com.iluwatar.abstractfactory;
/** /**

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; package com.iluwatar.abstractfactory;
/** /**

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; package com.iluwatar.abstractfactory;
/** /**

View File

@@ -0,0 +1,103 @@
/**
* 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;
/**
* Test for abstract factory
*/
public class AbstractFactoryTest {
private App app = new App();
private KingdomFactory elfFactory;
private KingdomFactory orcFactory;
@Before
public void setUp() {
elfFactory = new ElfKingdomFactory();
orcFactory = new OrcKingdomFactory();
}
@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,78 +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; 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.Test;
import java.io.IOException;
/**
* Tests that Abstract Factory example runs without errors.
*/
public class AppTest { 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 @Test
public void king() { public void test() throws IOException {
final King elfKing = app.getKing(elfFactory); String[] args = {};
assertTrue(elfKing instanceof ElfKing); App.main(args);
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());
} }
} }

134
adapter/README.md Normal file
View File

@@ -0,0 +1,134 @@
---
layout: pattern
title: Adapter
folder: adapter
permalink: /patterns/adapter/
pumlid: DSR14S8m30J0Lg20M7-wEMnDOiPMFDA9j0yyUEtUkzMHJTF7xI1NF4GSLzaxZtncgDVJgCPIpobzv0N2vOKtjgRHTziMI7KBcOXl10thfxB-Nz9dMJd71m00
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`
```
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
```
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.
```
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.
```
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

View File

@@ -1,33 +0,0 @@
---
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.
![alt text](./etc/adapter.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)
**Credits**
* [Design Patterns: Elements of Reusable Object-Oriented Software](http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612)

View File

@@ -1,11 +1,35 @@
<?xml version="1.0"?> <?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" <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"> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<parent> <parent>
<groupId>com.iluwatar</groupId> <groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId> <artifactId>java-design-patterns</artifactId>
<version>1.9.0</version> <version>1.17.0</version>
</parent> </parent>
<artifactId>adapter</artifactId> <artifactId>adapter</artifactId>
<dependencies> <dependencies>

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.adapter; package com.iluwatar.adapter;
/** /**
@@ -12,14 +34,14 @@ package com.iluwatar.adapter;
* object. This example uses the object adapter approach. * object. This example uses the object adapter approach.
* *
* <p> * <p>
* The Adapter ({@link BattleFishingBoat}) converts the interface of the adaptee class ( * The Adapter ({@link FishingBoatAdapter}) converts the interface of the adaptee class (
* {@link FishingBoat}) into a suitable one expected by the client ( {@link BattleShip} ). * {@link FishingBoat}) into a suitable one expected by the client ( {@link RowingBoat} ).
* *
* <p> * <p>
* The story of this implementation is this. <br> * The story of this implementation is this. <br>
* Pirates are coming! we need a {@link BattleShip} to fight! We have a {@link FishingBoat} and our * 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. We have no time to make up a new ship! we need to reuse this {@link FishingBoat}. The
* captain needs a battleship which can fire and move. The spec is in {@link BattleShip}. We will * 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}. * use the Adapter pattern to reuse {@link FishingBoat}.
* *
*/ */
@@ -31,8 +53,8 @@ public class App {
* @param args command line args * @param args command line args
*/ */
public static void main(String[] args) { public static void main(String[] args) {
Captain captain = new Captain(new BattleFishingBoat()); // The captain can only operate rowing boats but with adapter he is able to use fishing boats as well
captain.move(); Captain captain = new Captain(new FishingBoatAdapter());
captain.fire(); captain.row();
} }
} }

View File

@@ -1,29 +0,0 @@
package com.iluwatar.adapter;
/**
*
* Adapter class. Adapts the interface of the device ({@link FishingBoat}) into {@link BattleShip}
* interface expected by the client ({@link Captain}). <br>
* In this case we added a new function fire to suit the interface. We are reusing the
* {@link FishingBoat} without changing itself. The Adapter class can just map the functions of the
* Adaptee or add, delete features of the Adaptee.
*
*/
public class BattleFishingBoat implements BattleShip {
private FishingBoat boat;
public BattleFishingBoat() {
boat = new FishingBoat();
}
@Override
public void fire() {
System.out.println("fire!");
}
@Override
public void move() {
boat.sail();
}
}

View File

@@ -1,14 +0,0 @@
package com.iluwatar.adapter;
/**
* The interface expected by the client.<br>
* A Battleship can fire and move.
*
*/
public interface BattleShip {
void fire();
void move();
}

View File

@@ -1,33 +1,48 @@
/**
* 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; package com.iluwatar.adapter;
/** /**
* The Captain uses {@link BattleShip} to fight. <br> * The Captain uses {@link RowingBoat} to sail. <br>
* This is the client in the pattern. * This is the client in the pattern.
*/ */
public class Captain implements BattleShip { public class Captain implements RowingBoat {
private BattleShip battleship; private RowingBoat rowingBoat;
public Captain() { public Captain() {}
public Captain(RowingBoat rowingBoat) {
this.rowingBoat = rowingBoat;
} }
public Captain(BattleShip battleship) { public void setRowingBoat(RowingBoat rowingBoat) {
this.battleship = battleship; this.rowingBoat = rowingBoat;
}
public void setBattleship(BattleShip battleship) {
this.battleship = battleship;
} }
@Override @Override
public void fire() { public void row() {
battleship.fire(); rowingBoat.row();
}
@Override
public void move() {
battleship.move();
} }
} }

View File

@@ -1,18 +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; package com.iluwatar.adapter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** /**
* *
* Device class (adaptee in the pattern). We want to reuse this class * Device class (adaptee in the pattern). We want to reuse this class.
* Fishing boat moves by sailing.
* *
*/ */
public class FishingBoat { public class FishingBoat {
private static final Logger LOGGER = LoggerFactory.getLogger(FishingBoat.class);
public void sail() { public void sail() {
System.out.println("The Boat is moving to that place"); LOGGER.info("The fishing boat is sailing");
}
public void fish() {
System.out.println("fishing ...");
} }
} }

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

@@ -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

@@ -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.adapter; package com.iluwatar.adapter;
import org.junit.Before; import org.junit.Before;
@@ -17,9 +39,9 @@ public class AdapterPatternTest {
private Map<String, Object> beans; private Map<String, Object> beans;
private static final String BATTLESHIP_BEAN = "engineer"; private static final String FISHING_BEAN = "fisher";
private static final String CAPTAIN_BEAN = "captain"; private static final String ROWING_BEAN = "captain";
/** /**
* This method runs before the test execution and sets the bean objects in the beans Map. * This method runs before the test execution and sets the bean objects in the beans Map.
@@ -28,34 +50,29 @@ public class AdapterPatternTest {
public void setup() { public void setup() {
beans = new HashMap<>(); beans = new HashMap<>();
BattleFishingBoat battleFishingBoat = spy(new BattleFishingBoat()); FishingBoatAdapter fishingBoatAdapter = spy(new FishingBoatAdapter());
beans.put(BATTLESHIP_BEAN, battleFishingBoat); beans.put(FISHING_BEAN, fishingBoatAdapter);
Captain captain = new Captain(); Captain captain = new Captain();
captain.setBattleship((BattleFishingBoat) beans.get(BATTLESHIP_BEAN)); captain.setRowingBoat((FishingBoatAdapter) beans.get(FISHING_BEAN));
beans.put(CAPTAIN_BEAN, captain); beans.put(ROWING_BEAN, captain);
} }
/** /**
* This test asserts that when we use the move() method on a captain bean(client), it is * This test asserts that when we use the row() method on a captain bean(client), it is
* internally calling move method on the battleship object. The Adapter ({@link BattleFishingBoat} * 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 * ) converts the interface of the target class ( {@link FishingBoat}) into a suitable one
* expected by the client ({@link Captain} ). * expected by the client ({@link Captain} ).
*/ */
@Test @Test
public void testAdapter() { public void testAdapter() {
BattleShip captain = (BattleShip) beans.get(CAPTAIN_BEAN); RowingBoat captain = (RowingBoat) beans.get(ROWING_BEAN);
// when captain moves // when captain moves
captain.move(); captain.row();
// the captain internally calls the battleship object to move // the captain internally calls the battleship object to move
BattleShip battleship = (BattleShip) beans.get(BATTLESHIP_BEAN); RowingBoat adapter = (RowingBoat) beans.get(FISHING_BEAN);
verify(battleship).move(); verify(adapter).row();
// same with above with firing
captain.fire();
verify(battleship).fire();
} }
} }

View File

@@ -0,0 +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 java.io.IOException;
/**
* Tests that Adapter example runs without errors.
*/
public class AppTest {
@Test
public void test() throws IOException {
String[] args = {};
App.main(args);
}
}

View File

@@ -0,0 +1,30 @@
---
layout: pattern
title: Aggregator Microservices
folder: aggregator-microservices
permalink: /patterns/aggregator-microservices/
pumlid: JOov3SCm301NIGQGs7iRXYPa1g8ayB7NjuiKwGvtmBrbKC-Tq_hhY5Y-0HXUjKaS-Kbdepc2HrIQ2jBpma23BvvOTdPfeooCO1iEYlu0O6l63MDQKI6Rp-CKOWSE-ey_NzEqhjH-0m00
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,88 @@
<?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.17.0</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>junit</groupId>
<artifactId>junit</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 static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.when;
import org.junit.Before;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
/**
* Test Aggregation of domain objects
*/
public class AggregatorTest {
@InjectMocks
private Aggregator aggregator;
@Mock
private ProductInformationClient informationClient;
@Mock
private ProductInventoryClient inventoryClient;
@Before
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,43 @@
@startuml
package com.iluwatar.aggregator.microservices {
class Aggregator {
- informationClient : ProductInformationClient
- inventoryClient : ProductInventoryClient
+ Aggregator()
+ getProduct() : Product
}
class App {
+ App()
+ main(args : String[]) {static}
}
class Product {
- productInventories : int
- title : String
+ Product()
+ getProductInventories() : int
+ getTitle() : String
+ setProductInventories(productInventories : int)
+ setTitle(title : String)
}
interface ProductInformationClient {
+ getProductTitle() : String {abstract}
}
class ProductInformationClientImpl {
- LOGGER : Logger {static}
+ ProductInformationClientImpl()
+ getProductTitle() : String
}
interface ProductInventoryClient {
+ getProductInventories() : int {abstract}
}
class ProductInventoryClientImpl {
- LOGGER : Logger {static}
+ ProductInventoryClientImpl()
+ getProductInventories() : int
}
}
Aggregator --> "-informationClient" ProductInformationClient
Aggregator --> "-inventoryClient" ProductInventoryClient
ProductInformationClientImpl ..|> ProductInformationClient
ProductInventoryClientImpl ..|> ProductInventoryClient
@enduml

View File

@@ -0,0 +1,12 @@
@startuml
package com.iluwatar.information.microservice {
class InformationApplication {
+ InformationApplication()
+ main(args : String[]) {static}
}
class InformationController {
+ InformationController()
+ getProductTitle() : String
}
}
@enduml

View File

@@ -0,0 +1,12 @@
@startuml
package com.iluwatar.inventory.microservice {
class InventoryApplication {
+ InventoryApplication()
+ main(args : String[]) {static}
}
class InventoryController {
+ InventoryController()
+ getProductInventories() : int
}
}
@enduml

View File

@@ -0,0 +1,79 @@
<?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.17.0</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>junit</groupId>
<artifactId>junit</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,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.information.microservice;
import org.junit.Assert;
import org.junit.Test;
/**
* Test for Information Rest Controller
*/
public class InformationControllerTest {
@Test
public void shouldGetProductTitle() {
InformationController infoController = new InformationController();
String title = infoController.getProductTitle();
Assert.assertEquals("The Product Title.", title);
}
}

View File

@@ -0,0 +1,79 @@
<?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.17.0</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>junit</groupId>
<artifactId>junit</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,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.inventory.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 InventoryApplication {
public static void main(String[] args) {
SpringApplication.run(InventoryApplication.class, args);
}
}

View File

@@ -0,0 +1,45 @@
/**
* 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.inventory.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 product inventories
*/
@RestController
public class InventoryController {
/**
* Endpoint to retrieve a product's inventories.
*
* @return product inventory.
*/
@RequestMapping(value = "/inventories", method = RequestMethod.GET)
public int getProductInventories() {
return 5;
}
}

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=51516

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.inventory.microservice;
import org.junit.Assert;
import org.junit.Test;
/**
* Test Inventory Rest Controller
*/
public class InventoryControllerTest {
@Test
public void testGetProductInventories() throws Exception {
InventoryController inventoryController = new InventoryController();
int numberOfInventories = inventoryController.getProductInventories();
Assert.assertEquals(5, numberOfInventories);
}
}

View File

@@ -0,0 +1,63 @@
<?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>java-design-patterns</artifactId>
<groupId>com.iluwatar</groupId>
<version>1.17.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>aggregator-microservices</artifactId>
<packaging>pom</packaging>
<build>
<plugins>
<plugin>
<groupId>com.github.markusmo3.urm</groupId>
<artifactId>urm-maven-plugin</artifactId>
<version>${urm.version}</version>
<configuration combine.self="override">
<outputDirectory>${project.basedir}/../etc</outputDirectory>
<packages>
<param>com.iluwatar</param>
</packages>
<skipForProjects>
<!-- skip for parent project -->
<param>aggregator-microservices</param>
</skipForProjects>
</configuration>
</plugin>
</plugins>
</build>
<modules>
<module>information-microservice</module>
<module>aggregator-service</module>
<module>inventory-microservice</module>
</modules>
</project>

31
api-gateway/README.md Normal file
View File

@@ -0,0 +1,31 @@
---
layout: pattern
title: API Gateway
folder: api-gateway
permalink: /patterns/api-gateway/
pumlid: JSox3SCm303HLP819FRUXg49cO542_nOyFPncUvUSszHwhbpMdyT4TCt0CDLcyIHdtGsEZLOez8vG7ek33JuueLbPvUcPM84cpeCz2S0fvI6mGjluA1_b-Tt2N5D6tNcw3y0
categories: Architectural
tags:
- Java
- Difficulty-Intermediate
- Spring
---
## Intent
Aggregate calls to microservices in a single location: the API Gateway. The user makes a single
call to the API Gateway, and the API Gateway then calls each relevant microservice.
![alt text](./etc/api-gateway.png "API Gateway")
## Applicability
Use the API Gateway pattern when
* you're also using the Microservices pattern and need a single point of aggregation for your
microservice calls
## Credits
* [microservices.io - API Gateway](http://microservices.io/patterns/apigateway.html)
* [NGINX - Building Microservices: Using an API Gateway](https://www.nginx.com/blog/building-microservices-using-an-api-gateway/)

View File

@@ -0,0 +1,87 @@
<?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>api-gateway</artifactId>
<groupId>com.iluwatar</groupId>
<version>1.17.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>api-gateway-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>junit</groupId>
<artifactId>junit</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,64 @@
/**
* 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.api.gateway;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
/**
* The ApiGateway aggregates calls to microservices based on the needs of the individual clients.
*/
@RestController
public class ApiGateway {
@Resource
private ImageClient imageClient;
@Resource
private PriceClient priceClient;
/**
* Retrieves product information that desktop clients need
* @return Product information for clients on a desktop
*/
@RequestMapping("/desktop")
public DesktopProduct getProductDesktop() {
DesktopProduct desktopProduct = new DesktopProduct();
desktopProduct.setImagePath(imageClient.getImagePath());
desktopProduct.setPrice(priceClient.getPrice());
return desktopProduct;
}
/**
* Retrieves product information that mobile clients need
* @return Product information for clients on a mobile device
*/
@RequestMapping("/mobile")
public MobileProduct getProductMobile() {
MobileProduct mobileProduct = new MobileProduct();
mobileProduct.setPrice(priceClient.getPrice());
return mobileProduct;
}
}

View File

@@ -0,0 +1,66 @@
/**
* 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.api.gateway;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* With the Microservices pattern, a client may need data from multiple different microservices.
* If the client called each microservice directly, that could contribute to longer load times,
* since the client would have to make a network request for each microservice called. Moreover,
* having the client call each microservice directly ties the client to that microservice - if the
* internal implementations of the microservices change (for example, if two microservices are
* combined sometime in the future) or if the location (host and port) of a microservice changes,
* then every client that makes use of those microservices must be updated.
*
* <p>
* The intent of the API Gateway pattern is to alleviate some of these issues. In the API Gateway
* pattern, an additional entity (the API Gateway) is placed between the client and the
* microservices. The job of the API Gateway is to aggregate the calls to the microservices.
* Rather than the client calling each microservice individually, the client calls the API Gateway
* a single time. The API Gateway then calls each of the microservices that the client needs.
*
* <p>
* This implementation shows what the API Gateway pattern could look like for an e-commerce site.
* The {@link ApiGateway} makes calls to the Image and Price microservices using the
* {@link ImageClientImpl} and {@link PriceClientImpl} respectively. Customers viewing the site on a
* desktop device can see both price information and an image of a product, so the {@link ApiGateway}
* calls both of the microservices and aggregates the data in the {@link DesktopProduct} model.
* However, mobile users only see price information; they do not see a product image. For mobile
* users, the {@link ApiGateway} only retrieves price information, which it uses to populate the
* {@link MobileProduct}.
*/
@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,54 @@
/**
* 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.api.gateway;
/**
* Encapsulates all of the information that a desktop client needs to display a product.
*/
public class DesktopProduct {
/**
* The price of the product
*/
private String price;
/**
* The path to the image of the product
*/
private String imagePath;
public String getPrice() {
return price;
}
public void setPrice(String price) {
this.price = price;
}
public String getImagePath() {
return imagePath;
}
public void setImagePath(String imagePath) {
this.imagePath = imagePath;
}
}

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.api.gateway;
/**
* An interface used to communicate with the Image microservice
*/
public interface ImageClient {
String getImagePath();
}

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.api.gateway;
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.springframework.stereotype.Component;
import java.io.IOException;
/**
* An adapter to communicate with the Image microservice
*/
@Component
public class ImageClientImpl implements ImageClient {
/**
* Makes a simple HTTP Get request to the Image microservice
* @return The path to the image
*/
@Override
public String getImagePath() {
String response = null;
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
HttpGet httpGet = new HttpGet("http://localhost:50005/image-path");
try (CloseableHttpResponse httpResponse = httpClient.execute(httpGet)) {
response = EntityUtils.toString(httpResponse.getEntity());
}
} catch (IOException e) {
e.printStackTrace();
}
return response;
}
}

View File

@@ -0,0 +1,41 @@
/**
* 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.api.gateway;
/**
* Encapsulates all of the information that mobile client needs to display a product.
*/
public class MobileProduct {
/**
* The price of the product
*/
private String price;
public String getPrice() {
return price;
}
public void setPrice(String price) {
this.price = price;
}
}

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.api.gateway;
/**
* An interface used to communicate with the Price microservice
*/
public interface PriceClient {
String getPrice();
}

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.api.gateway;
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.springframework.stereotype.Component;
import java.io.IOException;
/**
* An adapter to communicate with the Price microservice
*/
@Component
public class PriceClientImpl implements PriceClient {
/**
* Makes a simple HTTP Get request to the Price microservice
* @return The price of the product
*/
@Override
public String getPrice() {
String response = null;
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
HttpGet httpGet = new HttpGet("http://localhost:50006/price");
try (CloseableHttpResponse httpResponse = httpClient.execute(httpGet)) {
response = EntityUtils.toString(httpResponse.getEntity());
}
} catch (IOException e) {
e.printStackTrace();
}
return 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,81 @@
/**
* 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.api.gateway;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.when;
import org.junit.Before;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
/**
* Test API Gateway Pattern
*/
public class ApiGatewayTest {
@InjectMocks
private ApiGateway apiGateway;
@Mock
private ImageClient imageClient;
@Mock
private PriceClient priceClient;
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
}
/**
* Tests getting the data for a desktop client
*/
@Test
public void testGetProductDesktop() {
String imagePath = "/product-image.png";
String price = "20";
when(imageClient.getImagePath()).thenReturn(imagePath);
when(priceClient.getPrice()).thenReturn(price);
DesktopProduct desktopProduct = apiGateway.getProductDesktop();
assertEquals(price, desktopProduct.getPrice());
assertEquals(imagePath, desktopProduct.getImagePath());
}
/**
* Tests getting the data for a mobile client
*/
@Test
public void testGetProductMobile() {
String price = "20";
when(priceClient.getPrice()).thenReturn(price);
MobileProduct mobileProduct = apiGateway.getProductMobile();
assertEquals(price, mobileProduct.getPrice());
}
}

View File

@@ -0,0 +1,48 @@
@startuml
package com.iluwatar.api.gateway {
class ApiGateway {
- imageClient : ImageClient
- priceClient : PriceClient
+ ApiGateway()
+ getProductDesktop() : DesktopProduct
+ getProductMobile() : MobileProduct
}
class App {
+ App()
+ main(args : String[]) {static}
}
class DesktopProduct {
- imagePath : String
- price : String
+ DesktopProduct()
+ getImagePath() : String
+ getPrice() : String
+ setImagePath(imagePath : String)
+ setPrice(price : String)
}
interface ImageClient {
+ getImagePath() : String {abstract}
}
class ImageClientImpl {
+ ImageClientImpl()
+ getImagePath() : String
}
class MobileProduct {
- price : String
+ MobileProduct()
+ getPrice() : String
+ setPrice(price : String)
}
interface PriceClient {
+ getPrice() : String {abstract}
}
class PriceClientImpl {
+ PriceClientImpl()
+ getPrice() : String
}
}
ApiGateway --> "-imageClient" ImageClient
ApiGateway --> "-priceClient" PriceClient
ImageClientImpl ..|> ImageClient
PriceClientImpl ..|> PriceClient
@enduml

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

View File

@@ -1,105 +1,93 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<class-diagram version="1.1.8" icons="true" automaticImage="PNG" always-add-relationships="false" generalizations="true" <class-diagram version="1.1.9" icons="true" automaticImage="PNG" always-add-relationships="false" generalizations="true"
realizations="true" associations="true" dependencies="false" nesting-relationships="true"> realizations="true" associations="true" dependencies="false" nesting-relationships="true" router="FAN">
<class id="1" language="java" name="com.iluwatar.chain.Request" project="chain" <class id="1" language="java" name="com.iluwatar.api.gateway.ApiGateway" project="api-gateway"
file="/chain/src/main/java/com/iluwatar/chain/Request.java" binary="false" corner="BOTTOM_RIGHT"> file="/api-gateway/api-gateway-service/src/main/java/com/iluwatar/api/gateway/ApiGateway.java" binary="false" corner="BOTTOM_RIGHT">
<position height="196" width="228" x="168" y="182"/> <position height="-1" width="-1" x="125" y="87"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true" <display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true"> sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/> <attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/> <operations public="true" package="true" protected="true" private="true" static="true"/>
</display> </display>
</class> </class>
<class id="2" language="java" name="com.iluwatar.chain.OrcOfficer" project="chain" <class id="2" language="java" name="com.iluwatar.api.gateway.DesktopProduct" project="api-gateway"
file="/chain/src/main/java/com/iluwatar/chain/OrcOfficer.java" binary="false" corner="BOTTOM_RIGHT"> file="/api-gateway/api-gateway-service/src/main/java/com/iluwatar/api/gateway/DesktopProduct.java" binary="false" corner="BOTTOM_RIGHT">
<position height="124" width="194" x="168" y="609"/> <position height="-1" width="-1" x="388" y="109"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true" <display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true"> sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/> <attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/> <operations public="true" package="true" protected="true" private="true" static="true"/>
</display> </display>
</class> </class>
<class id="3" language="java" name="com.iluwatar.chain.OrcCommander" project="chain" <interface id="3" language="java" name="com.iluwatar.api.gateway.ImageClient" project="api-gateway"
file="/chain/src/main/java/com/iluwatar/chain/OrcCommander.java" binary="false" corner="BOTTOM_RIGHT"> file="/api-gateway/api-gateway-service/src/main/java/com/iluwatar/api/gateway/ImageClient.java" binary="false" corner="BOTTOM_RIGHT">
<position height="124" width="217" x="402" y="609"/> <position height="81" width="129" x="13" y="197"/>
<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="4" language="java" name="com.iluwatar.api.gateway.ImageClientImpl" project="api-gateway"
file="/api-gateway/api-gateway-service/src/main/java/com/iluwatar/api/gateway/ImageClientImpl.java" binary="false" corner="BOTTOM_RIGHT">
<position height="99" width="129" x="13" y="325"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true" <display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true"> sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/> <attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/> <operations public="true" package="true" protected="true" private="true" static="true"/>
</display> </display>
</class> </class>
<class id="4" language="java" name="com.iluwatar.chain.RequestHandler" project="chain" <class id="5" language="java" name="com.iluwatar.api.gateway.MobileProduct" project="api-gateway"
file="/chain/src/main/java/com/iluwatar/chain/RequestHandler.java" binary="false" corner="BOTTOM_RIGHT"> file="/api-gateway/api-gateway-service/src/main/java/com/iluwatar/api/gateway/MobileProduct.java" binary="false" corner="BOTTOM_RIGHT">
<position height="141" width="218" x="451" y="418"/> <position height="-1" width="-1" x="376" y="293"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true" <display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true"> sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/> <attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/> <operations public="true" package="true" protected="true" private="true" static="true"/>
</display> </display>
</class> </class>
<class id="5" language="java" name="com.iluwatar.chain.OrcSoldier" project="chain" <interface id="6" language="java" name="com.iluwatar.api.gateway.PriceClient" project="api-gateway"
file="/chain/src/main/java/com/iluwatar/chain/OrcSoldier.java" binary="false" corner="BOTTOM_RIGHT"> file="/api-gateway/api-gateway-service/src/main/java/com/iluwatar/api/gateway/PriceClient.java" binary="false" corner="BOTTOM_RIGHT">
<position height="124" width="194" x="659" y="609"/> <position height="-1" width="-1" x="222" y="231"/>
<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.api.gateway.PriceClientImpl" project="api-gateway"
file="/api-gateway/api-gateway-service/src/main/java/com/iluwatar/api/gateway/PriceClientImpl.java" binary="false" corner="BOTTOM_RIGHT">
<position height="-1" width="-1" x="223" y="374"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true" <display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true"> sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/> <attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/> <operations public="true" package="true" protected="true" private="true" static="true"/>
</display> </display>
</class> </class>
<class id="6" language="java" name="com.iluwatar.chain.OrcKing" project="chain"
file="/chain/src/main/java/com/iluwatar/chain/OrcKing.java" binary="false" corner="BOTTOM_RIGHT">
<position height="124" width="188" x="451" y="182"/>
<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>
<enumeration id="7" language="java" name="com.iluwatar.chain.RequestType" project="chain"
file="/chain/src/main/java/com/iluwatar/chain/RequestType.java" binary="false" corner="BOTTOM_RIGHT">
<position height="142" width="243" x="168" y="418"/>
<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>
<association id="8"> <association id="8">
<end type="SOURCE" refId="6" navigable="false"> <end type="SOURCE" refId="1" navigable="false">
<attribute id="9" name="chain"/> <attribute id="9" name="imageClient"/>
<multiplicity id="10" minimum="0" maximum="1"/> <multiplicity id="10" minimum="0" maximum="1"/>
</end> </end>
<end type="TARGET" refId="4" navigable="true"/> <end type="TARGET" refId="3" navigable="true"/>
<display labels="true" multiplicity="true"/> <display labels="true" multiplicity="true"/>
</association> </association>
<association id="11"> <realization id="11">
<end type="SOURCE" refId="4" navigable="false"> <end type="SOURCE" refId="4"/>
<attribute id="12" name="next"/> <end type="TARGET" refId="3"/>
<multiplicity id="13" minimum="0" maximum="1"/> </realization>
</end> <association id="12">
<end type="TARGET" refId="4" navigable="true"/>
<display labels="true" multiplicity="true"/>
</association>
<generalization id="14">
<end type="SOURCE" refId="5"/>
<end type="TARGET" refId="4"/>
</generalization>
<association id="15">
<end type="SOURCE" refId="1" navigable="false"> <end type="SOURCE" refId="1" navigable="false">
<attribute id="16" name="requestType"/> <attribute id="13" name="priceClient"/>
<multiplicity id="17" minimum="0" maximum="1"/> <multiplicity id="14" minimum="0" maximum="1"/>
</end> </end>
<end type="TARGET" refId="7" navigable="true"/> <end type="TARGET" refId="6" navigable="true"/>
<display labels="true" multiplicity="true"/> <display labels="true" multiplicity="true"/>
</association> </association>
<generalization id="18"> <realization id="15">
<end type="SOURCE" refId="2"/> <end type="SOURCE" refId="7"/>
<end type="TARGET" refId="4"/> <end type="TARGET" refId="6"/>
</generalization> </realization>
<generalization id="19">
<end type="SOURCE" refId="3"/>
<end type="TARGET" refId="4"/>
</generalization>
<classifier-display autosize="true" stereotype="true" package="true" initial-value="false" signature="true" <classifier-display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true"> sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/> <attributes public="true" package="true" protected="true" private="true" static="true"/>

View File

@@ -0,0 +1,12 @@
@startuml
package com.iluwatar.image.microservice {
class ImageApplication {
+ ImageApplication()
+ main(args : String[]) {static}
}
class ImageController {
+ ImageController()
+ getImagePath() : String
}
}
@enduml

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