├── twin ├── .gitignore ├── etc │ ├── twin.png │ └── twin.urm.puml └── README.md ├── caching ├── .gitignore ├── etc │ └── caching.png └── README.md ├── data-bus ├── .gitignore ├── etc │ └── data-bus.urm.png └── README.md ├── marker ├── .gitignore ├── etc │ ├── marker.urm.puml │ └── MarkerDiagram.png ├── README.md └── src │ ├── main │ └── java │ │ └── Permission.java │ └── test │ └── java │ └── AppTest.java ├── factory-method ├── .gitignore ├── etc │ ├── factory-method.png │ └── factory-method_1.png └── src │ └── main │ └── java │ └── com │ └── iluwatar │ └── factory │ └── method │ └── Weapon.java ├── abstract-factory ├── .gitignore ├── etc │ ├── abstract-factory.png │ └── abstract-factory_1.png └── src │ └── main │ └── java │ └── com │ └── iluwatar │ └── abstractfactory │ ├── Army.java │ ├── King.java │ └── Castle.java ├── message-channel ├── .gitignore ├── etc │ ├── message-channel.png │ └── message-channel.urm.puml └── README.md ├── publish-subscribe ├── .gitignore ├── etc │ ├── publish-subscribe.png │ └── publish-subscribe.urm.puml └── README.md ├── naked-objects ├── integtests │ ├── .gitignore │ └── src │ │ └── test │ │ └── java │ │ └── domainapp │ │ └── integtests │ │ └── specs │ │ └── modules │ │ └── simple │ │ └── SimpleObjectSpec_listAllAndCreate.feature ├── etc │ ├── naked-objects.png │ └── naked-objects-dom.urm.puml ├── webapp │ ├── lib │ │ └── .gitignore │ ├── src │ │ └── main │ │ │ ├── jettyconsole │ │ │ ├── isis-banner.pdn │ │ │ └── isis-banner.png │ │ │ └── webapp │ │ │ ├── images │ │ │ └── spinning-icon.gif │ │ │ ├── about │ │ │ └── images │ │ │ │ └── isis-logo.png │ │ │ ├── css │ │ │ └── application.css │ │ │ └── scripts │ │ │ └── application.js │ └── ide │ │ ├── eclipse │ │ └── launch │ │ │ └── .gitignore │ │ └── intellij │ │ └── launch │ │ └── README.txt ├── README ├── dom │ └── src │ │ └── main │ │ └── java │ │ ├── domainapp │ │ └── dom │ │ │ ├── modules │ │ │ └── simple │ │ │ │ └── SimpleObject.png │ │ │ └── app │ │ │ └── homepage │ │ │ └── HomePageViewModel.png │ │ └── META-INF │ │ └── persistence.xml ├── .gitignore ├── README.md └── .gitattributes ├── extension-objects ├── etc │ ├── extension-objects.urm.puml │ └── extension_obj.png ├── README.md └── src │ └── main │ └── java │ └── abstractextensions │ ├── UnitExtension.java │ ├── SoldierExtension.java │ ├── SergeantExtension.java │ └── CommanderExtension.java ├── dao ├── etc │ └── dao.png └── README.md ├── tls ├── etc │ ├── tls.png │ └── tls.urm.puml └── README.md ├── chain ├── etc │ ├── chain.png │ └── chain_1.png └── src │ └── main │ └── java │ └── com │ └── iluwatar │ └── chain │ └── RequestType.java ├── event-queue ├── pom.xml ├── etc │ ├── model.png │ ├── Bass-Drum-1.aif │ ├── Bass-Drum-1.wav │ ├── Closed-Hi-Hat-1.aif │ ├── Closed-Hi-Hat-1.wav │ └── event-queue.urm.puml └── README.md ├── flux ├── etc │ └── flux.png ├── README.md └── src │ └── main │ └── java │ └── com │ └── iluwatar │ └── flux │ └── action │ └── ActionType.java ├── monad ├── etc │ ├── monad.png │ └── monad.urm.puml ├── src │ └── main │ │ └── java │ │ └── com │ │ └── iluwatar │ │ └── monad │ │ └── Sex.java └── README.md ├── mutex ├── etc │ ├── mutex.png │ └── mutex.urm.puml └── README.md ├── proxy ├── etc │ ├── proxy.png │ ├── proxy-concept.png │ └── proxy.urm.puml └── src │ └── main │ └── java │ └── com │ └── iluwatar │ └── proxy │ └── WizardTower.java ├── state └── etc │ ├── state.png │ ├── state_1.png │ └── state.urm.puml ├── bridge └── etc │ └── bridge.png ├── facade └── etc │ ├── facade.png │ └── facade_1.png ├── layers ├── etc │ └── layers.png ├── README.md └── src │ └── main │ └── java │ └── com │ └── iluwatar │ └── layers │ └── View.java ├── module ├── etc │ └── module.png ├── README.md ├── error.txt └── output.txt ├── adapter └── etc │ ├── adapter.png │ └── adapter.urm.puml ├── balking ├── etc │ ├── balking.png │ └── balking.urm.puml └── README.md ├── command └── etc │ └── command.png ├── hexagonal └── etc │ ├── layers.png │ ├── hexagonal.png │ └── ports_and_adapters.png ├── memento ├── etc │ ├── memento.png │ └── memento.urm.puml ├── README.md └── src │ └── main │ └── java │ └── com │ └── iluwatar │ └── memento │ └── StarMemento.java ├── promise └── etc │ └── promise.png ├── reactor └── etc │ └── reactor.png ├── visitor └── etc │ ├── visitor.png │ └── visitor_1.png ├── callback ├── etc │ ├── callback.png │ └── callback.urm.puml ├── README.md └── src │ └── main │ └── java │ └── com │ └── iluwatar │ └── callback │ └── Callback.java ├── iterator ├── etc │ ├── iterator.png │ ├── iterator_1.png │ └── iterator.urm.puml ├── README.md └── src │ └── main │ └── java │ └── com │ └── iluwatar │ └── iterator │ └── ItemType.java ├── mediator └── etc │ ├── mediator.png │ └── mediator_1.png ├── multiton ├── etc │ ├── multiton.png │ └── multiton.urm.puml └── README.md ├── observer └── etc │ ├── observer.png │ └── observer_1.png ├── property ├── etc │ └── property.png └── README.md ├── strategy └── etc │ ├── strategy.png │ ├── strategy_1.png │ └── strategy.urm.puml ├── composite └── etc │ ├── composite.png │ ├── composite_1.png │ └── composite.urm.puml ├── converter ├── etc │ └── Converter.png └── README.md ├── decorator └── etc │ ├── decorator.png │ └── decorator.urm.puml ├── delegation ├── etc │ ├── delegation.png │ └── delegation.urm.puml └── README.md ├── flyweight ├── etc │ ├── flyweight.png │ └── flyweight_1.png └── src │ └── main │ └── java │ └── com │ └── iluwatar │ └── flyweight │ └── Potion.java ├── monostate ├── etc │ ├── monostate.png │ └── monostate.urm.puml └── README.md ├── mute-idiom ├── etc │ ├── mute-idiom.png │ └── mute-idiom.urm.puml └── README.md ├── prototype └── etc │ ├── prototype.png │ └── prototype_1.png ├── repository ├── etc │ └── repository.png └── README.md ├── semaphore ├── etc │ ├── semaphore.png │ └── semaphore.urm.puml └── README.md ├── servant ├── src │ └── etc │ │ └── servant.jpg ├── etc │ └── servant-pattern.png └── README.md ├── singleton └── etc │ ├── singleton.png │ └── singleton_1.png ├── api-gateway ├── etc │ ├── api-gateway.png │ ├── price-microservice.urm.puml │ ├── image-microservice.urm.puml │ └── api-gateway-service.urm.puml ├── image-microservice │ ├── etc │ │ └── image-microservice.png │ └── src │ │ └── main │ │ └── resources │ │ └── application.properties ├── price-microservice │ ├── etc │ │ └── price-microservice.png │ └── src │ │ └── main │ │ └── resources │ │ └── application.properties ├── README.md └── api-gateway-service │ └── src │ └── main │ └── resources │ └── application.properties ├── data-mapper ├── etc │ ├── data-mapper.png │ └── data-mapper.urm.puml └── README.md ├── factory-kit ├── etc │ ├── factory-kit.png │ ├── factory-kit.ucls │ └── factory-kit.urm.puml ├── README.md └── src │ └── main │ └── java │ └── com │ └── iluwatar │ └── factorykit │ ├── Weapon.java │ └── WeaponType.java ├── interpreter └── etc │ ├── interpreter.png │ └── interpreter_1.png ├── null-object ├── etc │ ├── null-object.png │ └── null-object.urm.puml └── README.md ├── object-pool ├── etc │ ├── object-pool.png │ └── object-pool.urm.puml └── README.md ├── page-object ├── etc │ ├── page-object.png │ ├── page-object.urm.puml │ └── page-object.ucls └── README.md ├── poison-pill ├── etc │ └── poison-pill.png └── README.md ├── thread-pool ├── etc │ ├── thread-pool.png │ └── thread-pool.urm.puml └── README.md ├── event-aggregator └── etc │ └── classes.png ├── lazy-loading ├── etc │ ├── lazy-loading.png │ └── lazy-loading.urm.puml └── README.md ├── step-builder ├── etc │ └── step-builder.png └── README.md ├── value-object ├── etc │ ├── value-object.png │ └── value-object.urm.puml └── README.md ├── object-mother ├── etc │ ├── object-mother.png │ └── object-mother.urm.puml └── README.md ├── service-layer ├── etc │ └── service-layer.png └── README.md ├── specification ├── etc │ └── specification.png └── README.md ├── double-dispatch ├── etc │ └── double-dispatch.png └── README.md ├── event-driven-architecture └── etc │ └── eda.png ├── execute-around ├── etc │ ├── execute-around.png │ └── execute-around.urm.puml └── README.md ├── feature-toggle ├── etc │ └── feature-toggle.png └── README.md ├── fluentinterface └── etc │ └── fluentinterface.png ├── service-locator └── etc │ ├── service-locator.png │ └── service-locator.urm.puml ├── template-method └── etc │ ├── template-method.png │ ├── template-method_1.png │ └── template-method.urm.puml ├── tolerant-reader ├── etc │ ├── tolerant-reader.png │ └── tolerant-reader.urm.puml └── README.md ├── front-controller └── etc │ ├── front-controller.png │ └── front-controller.urm.puml ├── abstract-document ├── etc │ ├── abstract-document.png │ └── abstract-document-base.png └── README.md ├── business-delegate ├── etc │ └── business-delegate.png ├── README.md └── src │ └── main │ └── java │ └── com │ └── iluwatar │ └── business │ └── delegate │ └── ServiceType.java ├── producer-consumer ├── etc │ ├── producer-consumer.png │ └── producer-consumer.urm.puml └── README.md ├── event-asynchronous ├── etc │ └── event-asynchronous.png ├── src │ └── main │ │ └── resources │ │ └── config.properties └── README.md ├── guarded-suspension ├── etc │ ├── guarded-suspension.png │ └── guarded-suspension.urm.puml └── README.md ├── private-class-data ├── etc │ ├── private-class-data.png │ └── private-class-data.urm.puml └── README.md ├── reader-writer-lock └── etc │ └── reader-writer-lock.png ├── dependency-injection ├── etc │ ├── dependency-injection.png │ └── dependency-injection.urm.puml ├── README.md └── src │ └── main │ └── java │ └── com │ └── iluwatar │ └── dependency │ └── injection │ └── Wizard.java ├── half-sync-half-async └── etc │ ├── half-sync-half-async.png │ └── half-sync-half-async.urm.puml ├── intercepting-filter └── etc │ └── intercepting-filter.png ├── model-view-presenter ├── etc │ ├── model-view-presenter.png │ ├── model-view-presenter_1.png │ └── data │ │ └── test.txt └── README.md ├── queue-load-leveling ├── etc │ ├── queue-load-leveling.gif │ └── queue-load-leveling.urm.puml └── src │ └── main │ └── java │ └── com │ └── iluwatar │ └── queue │ └── load │ └── leveling │ └── Task.java ├── model-view-controller ├── etc │ └── model-view-controller.png └── README.md ├── double-checked-locking ├── etc │ ├── double-checked-locking.png │ ├── double_checked_locking_1.png │ └── double-checked-locking.urm.puml ├── README.md └── src │ └── main │ └── java │ └── com │ └── iluwatar │ └── doublechecked │ └── locking │ └── Item.java ├── aggregator-microservices ├── etc │ ├── aggregator-microservice.png │ ├── inventory-microservice.urm.puml │ ├── information-microservice.urm.puml │ └── aggregator-service.urm.puml ├── README.md ├── aggregator-service │ └── src │ │ └── main │ │ └── resources │ │ └── application.properties ├── inventory-microservice │ └── src │ │ └── main │ │ └── resources │ │ └── application.properties └── information-microservice │ └── src │ └── main │ └── resources │ └── application.properties ├── async-method-invocation └── etc │ └── async-method-invocation.png ├── CONTRIBUTING.MD ├── resource-acquisition-is-initialization ├── etc │ ├── resource-acquisition-is-initialization.png │ └── resource-acquisition-is-initialization.urm.puml └── README.md ├── .gitignore ├── CODE_COVERAGE.md ├── LICENSE.md └── exclude-pmd.properties /twin/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | -------------------------------------------------------------------------------- /caching/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | -------------------------------------------------------------------------------- /data-bus/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | -------------------------------------------------------------------------------- /marker/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | -------------------------------------------------------------------------------- /factory-method/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | -------------------------------------------------------------------------------- /abstract-factory/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | -------------------------------------------------------------------------------- /message-channel/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | -------------------------------------------------------------------------------- /publish-subscribe/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | -------------------------------------------------------------------------------- /marker/etc/marker.urm.puml: -------------------------------------------------------------------------------- 1 | @startuml 2 | @enduml -------------------------------------------------------------------------------- /naked-objects/integtests/.gitignore: -------------------------------------------------------------------------------- 1 | /translations.pot 2 | -------------------------------------------------------------------------------- /extension-objects/etc/extension-objects.urm.puml: -------------------------------------------------------------------------------- 1 | @startuml 2 | @enduml -------------------------------------------------------------------------------- /dao/etc/dao.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/dao/etc/dao.png -------------------------------------------------------------------------------- /tls/etc/tls.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/tls/etc/tls.png -------------------------------------------------------------------------------- /chain/etc/chain.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/chain/etc/chain.png -------------------------------------------------------------------------------- /event-queue/pom.xml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/event-queue/pom.xml -------------------------------------------------------------------------------- /flux/etc/flux.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/flux/etc/flux.png -------------------------------------------------------------------------------- /monad/etc/monad.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/monad/etc/monad.png -------------------------------------------------------------------------------- /mutex/etc/mutex.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/mutex/etc/mutex.png -------------------------------------------------------------------------------- /proxy/etc/proxy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/proxy/etc/proxy.png -------------------------------------------------------------------------------- /state/etc/state.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/state/etc/state.png -------------------------------------------------------------------------------- /twin/etc/twin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/twin/etc/twin.png -------------------------------------------------------------------------------- /bridge/etc/bridge.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/bridge/etc/bridge.png -------------------------------------------------------------------------------- /chain/etc/chain_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/chain/etc/chain_1.png -------------------------------------------------------------------------------- /facade/etc/facade.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/facade/etc/facade.png -------------------------------------------------------------------------------- /layers/etc/layers.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/layers/etc/layers.png -------------------------------------------------------------------------------- /module/etc/module.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/module/etc/module.png -------------------------------------------------------------------------------- /state/etc/state_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/state/etc/state_1.png -------------------------------------------------------------------------------- /adapter/etc/adapter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/adapter/etc/adapter.png -------------------------------------------------------------------------------- /balking/etc/balking.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/balking/etc/balking.png -------------------------------------------------------------------------------- /caching/etc/caching.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/caching/etc/caching.png -------------------------------------------------------------------------------- /command/etc/command.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/command/etc/command.png -------------------------------------------------------------------------------- /facade/etc/facade_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/facade/etc/facade_1.png -------------------------------------------------------------------------------- /hexagonal/etc/layers.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/hexagonal/etc/layers.png -------------------------------------------------------------------------------- /memento/etc/memento.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/memento/etc/memento.png -------------------------------------------------------------------------------- /promise/etc/promise.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/promise/etc/promise.png -------------------------------------------------------------------------------- /reactor/etc/reactor.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/reactor/etc/reactor.png -------------------------------------------------------------------------------- /visitor/etc/visitor.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/visitor/etc/visitor.png -------------------------------------------------------------------------------- /callback/etc/callback.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/callback/etc/callback.png -------------------------------------------------------------------------------- /event-queue/etc/model.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/event-queue/etc/model.png -------------------------------------------------------------------------------- /iterator/etc/iterator.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/iterator/etc/iterator.png -------------------------------------------------------------------------------- /mediator/etc/mediator.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/mediator/etc/mediator.png -------------------------------------------------------------------------------- /multiton/etc/multiton.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/multiton/etc/multiton.png -------------------------------------------------------------------------------- /observer/etc/observer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/observer/etc/observer.png -------------------------------------------------------------------------------- /property/etc/property.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/property/etc/property.png -------------------------------------------------------------------------------- /strategy/etc/strategy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/strategy/etc/strategy.png -------------------------------------------------------------------------------- /visitor/etc/visitor_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/visitor/etc/visitor_1.png -------------------------------------------------------------------------------- /composite/etc/composite.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/composite/etc/composite.png -------------------------------------------------------------------------------- /composite/etc/composite_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/composite/etc/composite_1.png -------------------------------------------------------------------------------- /converter/etc/Converter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/converter/etc/Converter.png -------------------------------------------------------------------------------- /data-bus/etc/data-bus.urm.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/data-bus/etc/data-bus.urm.png -------------------------------------------------------------------------------- /decorator/etc/decorator.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/decorator/etc/decorator.png -------------------------------------------------------------------------------- /delegation/etc/delegation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/delegation/etc/delegation.png -------------------------------------------------------------------------------- /flyweight/etc/flyweight.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/flyweight/etc/flyweight.png -------------------------------------------------------------------------------- /flyweight/etc/flyweight_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/flyweight/etc/flyweight_1.png -------------------------------------------------------------------------------- /hexagonal/etc/hexagonal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/hexagonal/etc/hexagonal.png -------------------------------------------------------------------------------- /iterator/etc/iterator_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/iterator/etc/iterator_1.png -------------------------------------------------------------------------------- /marker/etc/MarkerDiagram.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/marker/etc/MarkerDiagram.png -------------------------------------------------------------------------------- /mediator/etc/mediator_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/mediator/etc/mediator_1.png -------------------------------------------------------------------------------- /monostate/etc/monostate.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/monostate/etc/monostate.png -------------------------------------------------------------------------------- /mute-idiom/etc/mute-idiom.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/mute-idiom/etc/mute-idiom.png -------------------------------------------------------------------------------- /observer/etc/observer_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/observer/etc/observer_1.png -------------------------------------------------------------------------------- /prototype/etc/prototype.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/prototype/etc/prototype.png -------------------------------------------------------------------------------- /prototype/etc/prototype_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/prototype/etc/prototype_1.png -------------------------------------------------------------------------------- /proxy/etc/proxy-concept.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/proxy/etc/proxy-concept.png -------------------------------------------------------------------------------- /repository/etc/repository.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/repository/etc/repository.png -------------------------------------------------------------------------------- /semaphore/etc/semaphore.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/semaphore/etc/semaphore.png -------------------------------------------------------------------------------- /servant/src/etc/servant.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/servant/src/etc/servant.jpg -------------------------------------------------------------------------------- /singleton/etc/singleton.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/singleton/etc/singleton.png -------------------------------------------------------------------------------- /singleton/etc/singleton_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/singleton/etc/singleton_1.png -------------------------------------------------------------------------------- /strategy/etc/strategy_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/strategy/etc/strategy_1.png -------------------------------------------------------------------------------- /api-gateway/etc/api-gateway.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/api-gateway/etc/api-gateway.png -------------------------------------------------------------------------------- /data-mapper/etc/data-mapper.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/data-mapper/etc/data-mapper.png -------------------------------------------------------------------------------- /event-queue/etc/Bass-Drum-1.aif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/event-queue/etc/Bass-Drum-1.aif -------------------------------------------------------------------------------- /event-queue/etc/Bass-Drum-1.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/event-queue/etc/Bass-Drum-1.wav -------------------------------------------------------------------------------- /factory-kit/etc/factory-kit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/factory-kit/etc/factory-kit.png -------------------------------------------------------------------------------- /interpreter/etc/interpreter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/interpreter/etc/interpreter.png -------------------------------------------------------------------------------- /null-object/etc/null-object.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/null-object/etc/null-object.png -------------------------------------------------------------------------------- /object-pool/etc/object-pool.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/object-pool/etc/object-pool.png -------------------------------------------------------------------------------- /page-object/etc/page-object.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/page-object/etc/page-object.png -------------------------------------------------------------------------------- /poison-pill/etc/poison-pill.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/poison-pill/etc/poison-pill.png -------------------------------------------------------------------------------- /servant/etc/servant-pattern.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/servant/etc/servant-pattern.png -------------------------------------------------------------------------------- /thread-pool/etc/thread-pool.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/thread-pool/etc/thread-pool.png -------------------------------------------------------------------------------- /event-aggregator/etc/classes.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/event-aggregator/etc/classes.png -------------------------------------------------------------------------------- /interpreter/etc/interpreter_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/interpreter/etc/interpreter_1.png -------------------------------------------------------------------------------- /lazy-loading/etc/lazy-loading.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/lazy-loading/etc/lazy-loading.png -------------------------------------------------------------------------------- /step-builder/etc/step-builder.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/step-builder/etc/step-builder.png -------------------------------------------------------------------------------- /value-object/etc/value-object.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/value-object/etc/value-object.png -------------------------------------------------------------------------------- /event-queue/etc/Closed-Hi-Hat-1.aif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/event-queue/etc/Closed-Hi-Hat-1.aif -------------------------------------------------------------------------------- /event-queue/etc/Closed-Hi-Hat-1.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/event-queue/etc/Closed-Hi-Hat-1.wav -------------------------------------------------------------------------------- /hexagonal/etc/ports_and_adapters.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/hexagonal/etc/ports_and_adapters.png -------------------------------------------------------------------------------- /naked-objects/etc/naked-objects.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/naked-objects/etc/naked-objects.png -------------------------------------------------------------------------------- /object-mother/etc/object-mother.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/object-mother/etc/object-mother.png -------------------------------------------------------------------------------- /service-layer/etc/service-layer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/service-layer/etc/service-layer.png -------------------------------------------------------------------------------- /specification/etc/specification.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/specification/etc/specification.png -------------------------------------------------------------------------------- /double-dispatch/etc/double-dispatch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/double-dispatch/etc/double-dispatch.png -------------------------------------------------------------------------------- /event-driven-architecture/etc/eda.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/event-driven-architecture/etc/eda.png -------------------------------------------------------------------------------- /execute-around/etc/execute-around.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/execute-around/etc/execute-around.png -------------------------------------------------------------------------------- /extension-objects/etc/extension_obj.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/extension-objects/etc/extension_obj.png -------------------------------------------------------------------------------- /factory-method/etc/factory-method.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/factory-method/etc/factory-method.png -------------------------------------------------------------------------------- /factory-method/etc/factory-method_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/factory-method/etc/factory-method_1.png -------------------------------------------------------------------------------- /feature-toggle/etc/feature-toggle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/feature-toggle/etc/feature-toggle.png -------------------------------------------------------------------------------- /fluentinterface/etc/fluentinterface.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/fluentinterface/etc/fluentinterface.png -------------------------------------------------------------------------------- /message-channel/etc/message-channel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/message-channel/etc/message-channel.png -------------------------------------------------------------------------------- /service-locator/etc/service-locator.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/service-locator/etc/service-locator.png -------------------------------------------------------------------------------- /template-method/etc/template-method.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/template-method/etc/template-method.png -------------------------------------------------------------------------------- /tolerant-reader/etc/tolerant-reader.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/tolerant-reader/etc/tolerant-reader.png -------------------------------------------------------------------------------- /abstract-factory/etc/abstract-factory.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/abstract-factory/etc/abstract-factory.png -------------------------------------------------------------------------------- /front-controller/etc/front-controller.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/front-controller/etc/front-controller.png -------------------------------------------------------------------------------- /template-method/etc/template-method_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/template-method/etc/template-method_1.png -------------------------------------------------------------------------------- /abstract-document/etc/abstract-document.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/abstract-document/etc/abstract-document.png -------------------------------------------------------------------------------- /abstract-factory/etc/abstract-factory_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/abstract-factory/etc/abstract-factory_1.png -------------------------------------------------------------------------------- /business-delegate/etc/business-delegate.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/business-delegate/etc/business-delegate.png -------------------------------------------------------------------------------- /naked-objects/webapp/lib/.gitignore: -------------------------------------------------------------------------------- 1 | # 2 | # explicitly ignoring Microsoft JDBC4 jar 3 | # (cannot redistribute, licensing) 4 | # 5 | sqljdbc4.jar 6 | -------------------------------------------------------------------------------- /producer-consumer/etc/producer-consumer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/producer-consumer/etc/producer-consumer.png -------------------------------------------------------------------------------- /publish-subscribe/etc/publish-subscribe.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/publish-subscribe/etc/publish-subscribe.png -------------------------------------------------------------------------------- /event-asynchronous/etc/event-asynchronous.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/event-asynchronous/etc/event-asynchronous.png -------------------------------------------------------------------------------- /guarded-suspension/etc/guarded-suspension.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/guarded-suspension/etc/guarded-suspension.png -------------------------------------------------------------------------------- /private-class-data/etc/private-class-data.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/private-class-data/etc/private-class-data.png -------------------------------------------------------------------------------- /reader-writer-lock/etc/reader-writer-lock.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/reader-writer-lock/etc/reader-writer-lock.png -------------------------------------------------------------------------------- /abstract-document/etc/abstract-document-base.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/abstract-document/etc/abstract-document-base.png -------------------------------------------------------------------------------- /dependency-injection/etc/dependency-injection.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/dependency-injection/etc/dependency-injection.png -------------------------------------------------------------------------------- /half-sync-half-async/etc/half-sync-half-async.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/half-sync-half-async/etc/half-sync-half-async.png -------------------------------------------------------------------------------- /intercepting-filter/etc/intercepting-filter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/intercepting-filter/etc/intercepting-filter.png -------------------------------------------------------------------------------- /model-view-presenter/etc/model-view-presenter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/model-view-presenter/etc/model-view-presenter.png -------------------------------------------------------------------------------- /queue-load-leveling/etc/queue-load-leveling.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/queue-load-leveling/etc/queue-load-leveling.gif -------------------------------------------------------------------------------- /model-view-controller/etc/model-view-controller.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/model-view-controller/etc/model-view-controller.png -------------------------------------------------------------------------------- /model-view-presenter/etc/model-view-presenter_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/model-view-presenter/etc/model-view-presenter_1.png -------------------------------------------------------------------------------- /double-checked-locking/etc/double-checked-locking.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/double-checked-locking/etc/double-checked-locking.png -------------------------------------------------------------------------------- /aggregator-microservices/etc/aggregator-microservice.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/aggregator-microservices/etc/aggregator-microservice.png -------------------------------------------------------------------------------- /async-method-invocation/etc/async-method-invocation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/async-method-invocation/etc/async-method-invocation.png -------------------------------------------------------------------------------- /double-checked-locking/etc/double_checked_locking_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/double-checked-locking/etc/double_checked_locking_1.png -------------------------------------------------------------------------------- /api-gateway/image-microservice/etc/image-microservice.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/api-gateway/image-microservice/etc/image-microservice.png -------------------------------------------------------------------------------- /api-gateway/price-microservice/etc/price-microservice.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/api-gateway/price-microservice/etc/price-microservice.png -------------------------------------------------------------------------------- /naked-objects/webapp/src/main/jettyconsole/isis-banner.pdn: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/naked-objects/webapp/src/main/jettyconsole/isis-banner.pdn -------------------------------------------------------------------------------- /naked-objects/webapp/src/main/jettyconsole/isis-banner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/naked-objects/webapp/src/main/jettyconsole/isis-banner.png -------------------------------------------------------------------------------- /naked-objects/webapp/src/main/webapp/images/spinning-icon.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/naked-objects/webapp/src/main/webapp/images/spinning-icon.gif -------------------------------------------------------------------------------- /page-object/etc/page-object.urm.puml: -------------------------------------------------------------------------------- 1 | @startuml 2 | package com.iluwatar.pageobject { 3 | class App { 4 | - App() 5 | + main(args : String[]) {static} 6 | } 7 | } 8 | @enduml -------------------------------------------------------------------------------- /naked-objects/webapp/src/main/webapp/about/images/isis-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/naked-objects/webapp/src/main/webapp/about/images/isis-logo.png -------------------------------------------------------------------------------- /naked-objects/README: -------------------------------------------------------------------------------- 1 | This is an Apache Isis application created with the SimpleApp archetype. The usage instructions can be found at http://isis.apache.org/guides/ug.html#_ug_getting-started_simpleapp-archetype -------------------------------------------------------------------------------- /naked-objects/dom/src/main/java/domainapp/dom/modules/simple/SimpleObject.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/naked-objects/dom/src/main/java/domainapp/dom/modules/simple/SimpleObject.png -------------------------------------------------------------------------------- /naked-objects/dom/src/main/java/domainapp/dom/app/homepage/HomePageViewModel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/naked-objects/dom/src/main/java/domainapp/dom/app/homepage/HomePageViewModel.png -------------------------------------------------------------------------------- /message-channel/etc/message-channel.urm.puml: -------------------------------------------------------------------------------- 1 | @startuml 2 | package com.iluwatar.message.channel { 3 | class App { 4 | - LOGGER : Logger {static} 5 | + App() 6 | + main(args : String[]) {static} 7 | } 8 | } 9 | @enduml -------------------------------------------------------------------------------- /CONTRIBUTING.MD: -------------------------------------------------------------------------------- 1 | This is great you have something to contribute! 2 | 3 | Before going any further please read the [wiki](https://github.com/iluwatar/java-design-patterns/wiki) 4 | with conventions and rules we used for this project. 5 | -------------------------------------------------------------------------------- /publish-subscribe/etc/publish-subscribe.urm.puml: -------------------------------------------------------------------------------- 1 | @startuml 2 | package com.iluwatar.publish.subscribe { 3 | class App { 4 | - LOGGER : Logger {static} 5 | + App() 6 | + main(args : String[]) {static} 7 | } 8 | } 9 | @enduml -------------------------------------------------------------------------------- /resource-acquisition-is-initialization/etc/resource-acquisition-is-initialization.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biubiu/java-design-patterns/master/resource-acquisition-is-initialization/etc/resource-acquisition-is-initialization.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | .metadata 3 | .settings 4 | .classpath 5 | .project 6 | *.class 7 | # Package Files # 8 | *.jar 9 | *.war 10 | *.ear 11 | .idea 12 | *.iml 13 | *.swp 14 | datanucleus.log 15 | /bin/ 16 | /bin/ 17 | /bin/ 18 | *.log 19 | data-mapper/src/main/resources/log4j.xml 20 | -------------------------------------------------------------------------------- /api-gateway/etc/price-microservice.urm.puml: -------------------------------------------------------------------------------- 1 | @startuml 2 | package com.iluwatar.price.microservice { 3 | class PriceApplication { 4 | + PriceApplication() 5 | + main(args : String[]) {static} 6 | } 7 | class PriceController { 8 | + PriceController() 9 | + getPrice() : String 10 | } 11 | } 12 | @enduml -------------------------------------------------------------------------------- /api-gateway/etc/image-microservice.urm.puml: -------------------------------------------------------------------------------- 1 | @startuml 2 | package com.iluwatar.image.microservice { 3 | class ImageApplication { 4 | + ImageApplication() 5 | + main(args : String[]) {static} 6 | } 7 | class ImageController { 8 | + ImageController() 9 | + getImagePath() : String 10 | } 11 | } 12 | @enduml -------------------------------------------------------------------------------- /aggregator-microservices/etc/inventory-microservice.urm.puml: -------------------------------------------------------------------------------- 1 | @startuml 2 | package com.iluwatar.inventory.microservice { 3 | class InventoryApplication { 4 | + InventoryApplication() 5 | + main(args : String[]) {static} 6 | } 7 | class InventoryController { 8 | + InventoryController() 9 | + getProductInventories() : int 10 | } 11 | } 12 | @enduml -------------------------------------------------------------------------------- /aggregator-microservices/etc/information-microservice.urm.puml: -------------------------------------------------------------------------------- 1 | @startuml 2 | package com.iluwatar.information.microservice { 3 | class InformationApplication { 4 | + InformationApplication() 5 | + main(args : String[]) {static} 6 | } 7 | class InformationController { 8 | + InformationController() 9 | + getProductTitle() : String 10 | } 11 | } 12 | @enduml -------------------------------------------------------------------------------- /naked-objects/webapp/ide/eclipse/launch/.gitignore: -------------------------------------------------------------------------------- 1 | /SimpleApp-PROTOTYPE-jrebel.launch 2 | /SimpleApp-PROTOTYPE-no-fixtures.launch 3 | /SimpleApp-PROTOTYPE-with-fixtures.launch 4 | /SimpleApp-SERVER-no-fixtures.launch 5 | /SimpleApp-PROTOTYPE-jrebel.launch 6 | /SimpleApp-PROTOTYPE-no-fixtures.launch 7 | /SimpleApp-PROTOTYPE-with-fixtures.launch 8 | /SimpleApp-SERVER-no-fixtures.launch 9 | -------------------------------------------------------------------------------- /execute-around/etc/execute-around.urm.puml: -------------------------------------------------------------------------------- 1 | @startuml 2 | package com.iluwatar.execute.around { 3 | class App { 4 | + App() 5 | + main(args : String[]) {static} 6 | } 7 | interface FileWriterAction { 8 | + writeFile(FileWriter) {abstract} 9 | } 10 | class SimpleFileWriter { 11 | + SimpleFileWriter(filename : String, action : FileWriterAction) 12 | } 13 | } 14 | @enduml -------------------------------------------------------------------------------- /guarded-suspension/etc/guarded-suspension.urm.puml: -------------------------------------------------------------------------------- 1 | @startuml 2 | package com.iluwatar.guarded.suspension { 3 | class App { 4 | + App() 5 | + main(args : String[]) {static} 6 | } 7 | class GuardedQueue { 8 | - LOGGER : Logger {static} 9 | - sourceList : Queue 10 | + GuardedQueue() 11 | + get() : Integer 12 | + put(e : Integer) 13 | } 14 | } 15 | @enduml -------------------------------------------------------------------------------- /resource-acquisition-is-initialization/etc/resource-acquisition-is-initialization.urm.puml: -------------------------------------------------------------------------------- 1 | @startuml 2 | package com.iluwatar.resource.acquisition.is.initialization { 3 | class App { 4 | - LOGGER : Logger {static} 5 | + App() 6 | + main(args : String[]) {static} 7 | } 8 | class SlidingDoor { 9 | - LOGGER : Logger {static} 10 | + SlidingDoor() 11 | + close() 12 | } 13 | class TreasureChest { 14 | - LOGGER : Logger {static} 15 | + TreasureChest() 16 | + close() 17 | } 18 | } 19 | @enduml -------------------------------------------------------------------------------- /CODE_COVERAGE.md: -------------------------------------------------------------------------------- 1 | # Code Coverage Report generation 2 | 3 | To generate the code coverage report, execute the following command: 4 | > mvn clean verify 5 | 6 | This will generate code coverage report in each of the modules. In order to view the same, open the following file in your browser. 7 | > target/site/jacoco/index.html 8 | 9 | Please note that the above folder is created under each of the modules. For example: 10 | * adapter/target/site/jacoco/index.html 11 | * busniess-delegate/target/site/jacoco/index.html 12 | 13 | 14 | -------------------------------------------------------------------------------- /double-checked-locking/etc/double-checked-locking.urm.puml: -------------------------------------------------------------------------------- 1 | @startuml 2 | package com.iluwatar.doublechecked.locking { 3 | class App { 4 | - LOGGER : Logger {static} 5 | + App() 6 | + main(args : String[]) {static} 7 | } 8 | class Inventory { 9 | - LOGGER : Logger {static} 10 | - inventorySize : int 11 | - items : List 12 | - lock : Lock 13 | + Inventory(inventorySize : int) 14 | + addItem(item : Item) : boolean 15 | + getItems() : List 16 | } 17 | class Item { 18 | + Item() 19 | } 20 | } 21 | Inventory --> "-items" Item 22 | @enduml -------------------------------------------------------------------------------- /mutex/etc/mutex.urm.puml: -------------------------------------------------------------------------------- 1 | @startuml 2 | package com.iluwatar.mutex { 3 | class App { 4 | + App() 5 | + main(args : String[]) {static} 6 | } 7 | class Jar { 8 | - beans : int 9 | - lock : Lock 10 | + Jar(beans : int, lock : Lock) 11 | + takeBean() : boolean 12 | } 13 | interface Lock { 14 | + acquire() {abstract} 15 | + release() {abstract} 16 | } 17 | class Mutex { 18 | - owner : Object 19 | + Mutex() 20 | + acquire() 21 | + getOwner() : Object 22 | + release() 23 | } 24 | } 25 | Jar --> "-lock" Lock 26 | Mutex ..|> Lock 27 | @enduml -------------------------------------------------------------------------------- /naked-objects/.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | *.swp 3 | *.class 4 | bin/ 5 | target/ 6 | target-ide/ 7 | logs/ 8 | .settings/ 9 | .project 10 | .classpath 11 | .idea 12 | *.iml 13 | 14 | JArchitectOut/ 15 | *.jdproj 16 | 17 | neo4j_DB/ 18 | 19 | # log files 20 | datanucleus.log 21 | isis.log 22 | i18n-po.log 23 | hs_err_pid*.log 24 | 25 | # Package Files # 26 | *.jar 27 | *.war 28 | *.ear 29 | 30 | dependency-reduced-pom.xml 31 | pom.xml.tag 32 | pom.xml.next 33 | pom.xml.releaseBackup 34 | pom.xml.versionsBackup 35 | 36 | .clover/ 37 | *.jdproj 38 | JArchitectOut/ 39 | 40 | 41 | rebel.xml 42 | /translations.pot 43 | -------------------------------------------------------------------------------- /twin/etc/twin.urm.puml: -------------------------------------------------------------------------------- 1 | @startuml 2 | package com.iluwatar.twin { 3 | class App { 4 | + App() 5 | + main(args : String[]) {static} 6 | - waiting() {static} 7 | } 8 | class BallItem { 9 | - LOGGER : Logger {static} 10 | - isSuspended : boolean 11 | - twin : BallThread 12 | + BallItem() 13 | + click() 14 | + doDraw() 15 | + move() 16 | + setTwin(twin : BallThread) 17 | } 18 | abstract class GameItem { 19 | - LOGGER : Logger {static} 20 | + GameItem() 21 | + click() {abstract} 22 | + doDraw() {abstract} 23 | + draw() 24 | } 25 | } 26 | BallItem --|> GameItem 27 | @enduml -------------------------------------------------------------------------------- /value-object/etc/value-object.urm.puml: -------------------------------------------------------------------------------- 1 | @startuml 2 | package com.iluwatar.value.object { 3 | class App { 4 | - LOGGER : Logger {static} 5 | + App() 6 | + main(args : String[]) {static} 7 | } 8 | class HeroStat { 9 | - intelligence : int 10 | - luck : int 11 | - strength : int 12 | - HeroStat(strength : int, intelligence : int, luck : int) 13 | + equals(obj : Object) : boolean 14 | + getIntelligence() : int 15 | + getLuck() : int 16 | + getStrength() : int 17 | + hashCode() : int 18 | + toString() : String 19 | + valueOf(strength : int, intelligence : int, luck : int) : HeroStat {static} 20 | } 21 | } 22 | @enduml -------------------------------------------------------------------------------- /callback/etc/callback.urm.puml: -------------------------------------------------------------------------------- 1 | @startuml 2 | package com.iluwatar.callback { 3 | class App { 4 | - LOGGER : Logger {static} 5 | + App() 6 | + main(args : String[]) {static} 7 | } 8 | interface Callback { 9 | + call() {abstract} 10 | } 11 | class LambdasApp { 12 | - LOGGER : Logger {static} 13 | + LambdasApp() 14 | + main(args : String[]) {static} 15 | } 16 | class SimpleTask { 17 | - LOGGER : Logger {static} 18 | + SimpleTask() 19 | + execute() 20 | } 21 | abstract class Task { 22 | + Task() 23 | + execute() {abstract} 24 | + executeWith(callback : Callback) 25 | } 26 | } 27 | SimpleTask --|> Task 28 | @enduml -------------------------------------------------------------------------------- /tls/etc/tls.urm.puml: -------------------------------------------------------------------------------- 1 | @startuml 2 | package com.iluwatar.tls { 3 | class App { 4 | + App() 5 | + main(args : String[]) {static} 6 | - printAndCountDates(res : Result) : int {static} 7 | - printAndCountExceptions(res : Result) : int {static} 8 | } 9 | class DateFormatCallable { 10 | - dateValue : String 11 | - df : ThreadLocal 12 | + DateFormatCallable(inDateFormat : String, inDateValue : String) 13 | + call() : Result 14 | } 15 | class Result { 16 | - dateList : List 17 | - exceptionList : List 18 | + Result() 19 | + getDateList() : List 20 | + getExceptionList() : List 21 | } 22 | } 23 | @enduml -------------------------------------------------------------------------------- /mute-idiom/etc/mute-idiom.urm.puml: -------------------------------------------------------------------------------- 1 | @startuml 2 | package com.iluwatar.mute { 3 | class App { 4 | - LOGGER : Logger {static} 5 | + App() 6 | - acquireResource() : Resource {static} 7 | - closeResource(resource : Resource) {static} 8 | + main(args : String[]) {static} 9 | - useOfLoggedMute() {static} 10 | - useOfMute() {static} 11 | - utilizeResource(resource : Resource) {static} 12 | } 13 | interface CheckedRunnable { 14 | + run() {abstract} 15 | } 16 | class Mute { 17 | - Mute() 18 | + loggedMute(runnable : CheckedRunnable) {static} 19 | + mute(runnable : CheckedRunnable) {static} 20 | } 21 | interface Resource { 22 | } 23 | } 24 | @enduml -------------------------------------------------------------------------------- /publish-subscribe/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: pattern 3 | title: Publish Subscribe 4 | folder: publish-subscribe 5 | permalink: /patterns/publish-subscribe/ 6 | categories: Integration 7 | tags: 8 | - Java 9 | - EIP 10 | - Apache Camel™ 11 | --- 12 | 13 | ## Intent 14 | Broadcast messages from sender to all the interested receivers. 15 | 16 | ![alt text](./etc/publish-subscribe.png "Publish Subscribe Channel") 17 | 18 | ## Applicability 19 | Use the Publish Subscribe Channel pattern when 20 | 21 | * two or more applications need to communicate using a messaging system for broadcasts. 22 | 23 | ## Credits 24 | 25 | * [J2EE Design Patterns](http://www.amazon.com/J2EE-Design-Patterns-William-Crawford/dp/0596004273/ref=sr_1_2) 26 | -------------------------------------------------------------------------------- /balking/etc/balking.urm.puml: -------------------------------------------------------------------------------- 1 | @startuml 2 | package com.iluwatar.balking { 3 | class App { 4 | - LOGGER : Logger {static} 5 | + App() 6 | + main(args : String[]) {static} 7 | } 8 | class WashingMachine { 9 | - LOGGER : Logger {static} 10 | - washingMachineState : WashingMachineState 11 | + WashingMachine() 12 | + endOfWashing() 13 | + getWashingMachineState() : WashingMachineState 14 | + wash() 15 | } 16 | enum WashingMachineState { 17 | + ENABLED {static} 18 | + WASHING {static} 19 | + valueOf(name : String) : WashingMachineState {static} 20 | + values() : WashingMachineState[] {static} 21 | } 22 | } 23 | WashingMachine --> "-washingMachineState" WashingMachineState 24 | @enduml -------------------------------------------------------------------------------- /message-channel/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: pattern 3 | title: Message Channel 4 | folder: message-channel 5 | permalink: /patterns/message-channel/ 6 | categories: Integration 7 | tags: 8 | - Java 9 | - EIP 10 | - Apache Camel™ 11 | --- 12 | 13 | ## Intent 14 | When two applications communicate using a messaging system they do it by using logical addresses 15 | of the system, so called Message Channels. 16 | 17 | ![alt text](./etc/message-channel.png "Message Channel") 18 | 19 | ## Applicability 20 | Use the Message Channel pattern when 21 | 22 | * two or more applications need to communicate using a messaging system 23 | 24 | ## Real world examples 25 | 26 | * [akka-camel](http://doc.akka.io/docs/akka/snapshot/scala/camel.html) 27 | -------------------------------------------------------------------------------- /multiton/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: pattern 3 | title: Multiton 4 | folder: multiton 5 | permalink: /patterns/multiton/ 6 | pumlid: FST14i8m20NGg-W16lRUXgPCYnD81Zxs-hfozzvJlOywf68yBc3bYoZuRgVYghrIea-7E5gVHZhgPd3Gcp-y7P9w-hOOaF0au_o1h0OKqqdG_saLrbRP-080 7 | categories: Creational 8 | tags: 9 | - Java 10 | - Difficulty-Beginner 11 | --- 12 | 13 | ## Also known as 14 | Registry 15 | 16 | ## Intent 17 | Ensure a class only has limited number of instances, and provide a 18 | global point of access to them. 19 | 20 | ![alt text](./etc/multiton.png "Multiton") 21 | 22 | ## Applicability 23 | Use the Multiton pattern when 24 | 25 | * there must be specific number of instances of a class, and they must be accessible to clients from a well-known access point 26 | -------------------------------------------------------------------------------- /page-object/etc/page-object.ucls: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /balking/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: pattern 3 | title: Balking 4 | folder: balking 5 | permalink: /patterns/balking/ 6 | categories: Concurrency 7 | tags: 8 | - Java 9 | - Difficulty-Beginner 10 | --- 11 | 12 | ## Intent 13 | Balking Pattern is used to prevent an object from executing certain code if it is an 14 | incomplete or inappropriate state 15 | 16 | ![alt text](./etc/balking.png "Balking") 17 | 18 | ## Applicability 19 | Use the Balking pattern when 20 | 21 | *you want to invoke an action on an object only when it is in a particular state 22 | *objects are generally only in a state that is prone to balking temporarily 23 | but for an unknown amount of time 24 | 25 | ## Related patterns 26 | * Guarded Suspendion Pattern 27 | * Double Checked Locking Pattern -------------------------------------------------------------------------------- /object-pool/etc/object-pool.urm.puml: -------------------------------------------------------------------------------- 1 | @startuml 2 | package com.iluwatar.object.pool { 3 | class App { 4 | - LOGGER : Logger {static} 5 | + App() 6 | + main(args : String[]) {static} 7 | } 8 | abstract class ObjectPool { 9 | - available : Set 10 | - inUse : Set 11 | + ObjectPool() 12 | + checkIn(instance : T) 13 | + checkOut() : T 14 | # create() : T {abstract} 15 | + toString() : String 16 | } 17 | class Oliphaunt { 18 | - counter : int {static} 19 | - id : int 20 | + Oliphaunt() 21 | + getId() : int 22 | + toString() : String 23 | } 24 | class OliphauntPool { 25 | + OliphauntPool() 26 | # create() : Oliphaunt 27 | } 28 | } 29 | OliphauntPool --|> ObjectPool 30 | @enduml -------------------------------------------------------------------------------- /event-queue/etc/event-queue.urm.puml: -------------------------------------------------------------------------------- 1 | @startuml 2 | package com.iluwatar.event.queue { 3 | class App { 4 | + App() 5 | + getAudioStream(filePath : String) : AudioInputStream {static} 6 | + main(args : String[]) {static} 7 | } 8 | class Audio { 9 | - MAX_PENDING : int {static} 10 | - headIndex : int {static} 11 | - pendingAudio : PlayMessage[] {static} 12 | - tailIndex : int {static} 13 | - updateThread : Thread {static} 14 | + Audio() 15 | + init() {static} 16 | + playSound(stream : AudioInputStream, volume : float) {static} 17 | + stopService() {static} 18 | + update() {static} 19 | } 20 | class PlayMessage { 21 | ~ stream : AudioInputStream 22 | ~ volume : float 23 | + PlayMessage() 24 | } 25 | } 26 | @enduml -------------------------------------------------------------------------------- /factory-kit/etc/factory-kit.ucls: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /guarded-suspension/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: pattern 3 | title: Guarded Suspension 4 | folder: guarded-suspension 5 | permalink: /patterns/guarded-suspension/ 6 | pumlid: ROux3W8n30LxJW47IDnJxLLCOcMD4YVoXxq-eQTwev56UeSvgiVejmTBwL4fjDzFzsLF0CKhD_OpNc6aPOgJU2vp0FUuSAVmnW-cIiPDqa9tKZ4OQ1kW1MgbcYniaHXF0VBoH-VGaTVlnK5Iztu1 7 | categories: Concurrency 8 | tags: 9 | - Java 10 | - Difficulty-Beginner 11 | --- 12 | 13 | ## Intent 14 | Use Guarded suspension pattern to handle a situation when you want to execute a method on object which is not in a proper state. 15 | 16 | ![Guarded Suspension diagram](./etc/guarded-suspension.png) 17 | 18 | ## Applicability 19 | Use Guarded Suspension pattern when the developer knows that the method execution will be blocked for a finite period of time 20 | 21 | ## Related patterns 22 | * Balking 23 | -------------------------------------------------------------------------------- /private-class-data/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: pattern 3 | title: Private Class Data 4 | folder: private-class-data 5 | permalink: /patterns/private-class-data/ 6 | pumlid: RShR3SCm243HLTe1RFwx3S4eeSB4uf6itmpGlwkZ-nOZhS7b-ZeoLtm07E--InwrLR3JQScMdSu9edLZeiCNBso3GtPh2pFPBM1YF07BvSBaHeeHRJm_SD8VxkMphvhw0m00 7 | categories: Other 8 | tags: 9 | - Java 10 | - Difficulty-Beginner 11 | - Idiom 12 | --- 13 | 14 | ## Intent 15 | Private Class Data design pattern seeks to reduce exposure of 16 | attributes by limiting their visibility. It reduces the number of class 17 | attributes by encapsulating them in single Data object. 18 | 19 | ![alt text](./etc/private-class-data.png "Private Class Data") 20 | 21 | ## Applicability 22 | Use the Private Class Data pattern when 23 | 24 | * you want to prevent write access to class data members 25 | -------------------------------------------------------------------------------- /property/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: pattern 3 | title: Property 4 | folder: property 5 | permalink: /patterns/property/ 6 | pumlid: FSV13OCm30NGLTe1YEziumOBKYMEPN-3s9wUUdlltRJst2Izlmx0OYLolihUSEGdGxnEXIXAdODQpul1Jby-UTaasgwBCI2kGOFZ1pAV9ewR1FMVaZwAvUWF 7 | categories: Creational 8 | tags: 9 | - Java 10 | - Difficulty-Beginner 11 | --- 12 | 13 | ## Intent 14 | Create hierarchy of objects and new objects using already existing 15 | objects as parents. 16 | 17 | ![alt text](./etc/property.png "Property") 18 | 19 | ## Applicability 20 | Use the Property pattern when 21 | 22 | * when you like to have objects with dynamic set of fields and prototype inheritance 23 | 24 | ## Real world examples 25 | 26 | * [JavaScript](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Inheritance_and_the_prototype_chain) prototype inheritance 27 | -------------------------------------------------------------------------------- /poison-pill/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: pattern 3 | title: Poison Pill 4 | folder: poison-pill 5 | permalink: /patterns/poison-pill/ 6 | pumlid: JSZ14SCm20NHLf82BExfXiYCJGOX3NpYzkDZRllsgTwjTgcmnmciV145N-rGdFMkbEZJ8OxMvo2rkXWSzE4lRxka7huj1YGyQN3UGMjgpdkh6Gdwlrl5QAk6_G00 7 | categories: Other 8 | tags: 9 | - Java 10 | - Difficulty-Intermediate 11 | - Reactive 12 | --- 13 | 14 | ## Intent 15 | Poison Pill is known predefined data item that allows to provide 16 | graceful shutdown for separate distributed consumption process. 17 | 18 | ![alt text](./etc/poison-pill.png "Poison Pill") 19 | 20 | ## Applicability 21 | Use the Poison Pill idiom when 22 | 23 | * need to send signal from one thread/process to another to terminate 24 | 25 | ## Real world examples 26 | 27 | * [akka.actor.PoisonPill](http://doc.akka.io/docs/akka/2.1.4/java/untyped-actors.html) 28 | -------------------------------------------------------------------------------- /multiton/etc/multiton.urm.puml: -------------------------------------------------------------------------------- 1 | @startuml 2 | package com.iluwatar.multiton { 3 | class App { 4 | - LOGGER : Logger {static} 5 | + App() 6 | + main(args : String[]) {static} 7 | } 8 | class Nazgul { 9 | - name : NazgulName 10 | - nazguls : Map {static} 11 | - Nazgul(name : NazgulName) 12 | + getInstance(name : NazgulName) : Nazgul {static} 13 | + getName() : NazgulName 14 | } 15 | enum NazgulName { 16 | + ADUNAPHEL {static} 17 | + AKHORAHIL {static} 18 | + DWAR {static} 19 | + HOARMURATH {static} 20 | + JI_INDUR {static} 21 | + KHAMUL {static} 22 | + MURAZOR {static} 23 | + REN {static} 24 | + UVATHA {static} 25 | + valueOf(name : String) : NazgulName {static} 26 | + values() : NazgulName[] {static} 27 | } 28 | } 29 | Nazgul --> "-name" NazgulName 30 | @enduml -------------------------------------------------------------------------------- /proxy/etc/proxy.urm.puml: -------------------------------------------------------------------------------- 1 | @startuml 2 | package com.iluwatar.proxy { 3 | class App { 4 | + App() 5 | + main(args : String[]) {static} 6 | } 7 | class IvoryTower { 8 | - LOGGER : Logger {static} 9 | + IvoryTower() 10 | + enter(wizard : Wizard) 11 | } 12 | class Wizard { 13 | - name : String 14 | + Wizard(name : String) 15 | + toString() : String 16 | } 17 | interface WizardTower { 18 | + enter(Wizard) {abstract} 19 | } 20 | class WizardTowerProxy { 21 | - LOGGER : Logger {static} 22 | - NUM_WIZARDS_ALLOWED : int {static} 23 | - numWizards : int 24 | - tower : WizardTower 25 | + WizardTowerProxy(tower : WizardTower) 26 | + enter(wizard : Wizard) 27 | } 28 | } 29 | WizardTowerProxy --> "-tower" WizardTower 30 | IvoryTower ..|> WizardTower 31 | WizardTowerProxy ..|> WizardTower 32 | @enduml -------------------------------------------------------------------------------- /twin/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: pattern 3 | title: Twin 4 | folder: twin 5 | permalink: /patterns/twin/ 6 | pumlid: 7SR13OCm30NGLUW0n7UsCS42eyH4zdUpFbNVwNtKQij3qjjo0ICs8kTPJiMLUuPuVGnYAFNff2qdWvrk_l9wIEXfws10t88wno-4gKQ2-az9xsLaRoy0 7 | categories: Creational 8 | tags: 9 | - Java 10 | - Difficulty-Intermediate 11 | --- 12 | 13 | ## Intent 14 | Twin pattern is a design pattern which provides a standard solution to simulate multiple 15 | inheritance in java 16 | 17 | ![alt text](./etc/twin.png "Twin") 18 | 19 | ## Applicability 20 | Use the Twin idiom when 21 | 22 | * to simulate multiple inheritance in a language that does not support this feature. 23 | * to avoid certain problems of multiple inheritance such as name clashes. 24 | 25 | ## Credits 26 | 27 | * [Twin – A Design Pattern for Modeling Multiple Inheritance](http://www.ssw.uni-linz.ac.at/Research/Papers/Moe99/Paper.pdf) 28 | -------------------------------------------------------------------------------- /resource-acquisition-is-initialization/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: pattern 3 | title: Resource Acquisition Is Initialization 4 | folder: resource-acquisition-is-initialization 5 | permalink: /patterns/resource-acquisition-is-initialization/ 6 | pumlid: ZShR3S8m343HLUW0YV_PnhXMQvGumOzMOdhA1lqxkhgBABLSEQqzzeZfJm33isuIUxxIsMXei4QbqK5QdXXeyCO3oyekcvQ94MpgqD4lWB6FDEA2z4bn2HbQn8leHMponNy13hgvrhHUP_Rs0m00 7 | categories: Other 8 | tags: 9 | - Java 10 | - Difficulty-Beginner 11 | - Idiom 12 | --- 13 | 14 | ## Intent 15 | Resource Acquisition Is Initialization pattern can be used to implement exception safe resource management. 16 | 17 | ![alt text](./etc/resource-acquisition-is-initialization.png "Resource Acquisition Is Initialization") 18 | 19 | ## Applicability 20 | Use the Resource Acquisition Is Initialization pattern when 21 | 22 | * you have resources that must be closed in every condition 23 | -------------------------------------------------------------------------------- /dao/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: pattern 3 | title: Data Access Object 4 | folder: dao 5 | permalink: /patterns/dao/ 6 | pumlid: 5SR14OKW30N0LhG0oVrt4o6ZE12Ov4NR_thQNQlc5aN2sd82qtz4naywAixOmyNoK8WYvT6fjdWOR7JnpLiHhuTkam4nTUhiRwZm847-J64zpUZj3m00 7 | categories: Persistence Tier 8 | tags: 9 | - Java 10 | - Difficulty-Beginner 11 | --- 12 | 13 | ## Intent 14 | Object provides an abstract interface to some type of database or 15 | other persistence mechanism. 16 | 17 | ![alt text](./etc/dao.png "Data Access Object") 18 | 19 | ## Applicability 20 | Use the Data Access Object in any of the following situations 21 | 22 | * when you want to consolidate how the data layer is accessed 23 | * when you want to avoid writing multiple data retrieval/persistence layers 24 | 25 | ## Credits 26 | 27 | * [J2EE Design Patterns](http://www.amazon.com/J2EE-Design-Patterns-William-Crawford/dp/0596004273/ref=sr_1_2) 28 | -------------------------------------------------------------------------------- /monostate/etc/monostate.urm.puml: -------------------------------------------------------------------------------- 1 | @startuml 2 | package com.iluwatar.monostate { 3 | class App { 4 | + App() 5 | + main(args : String[]) {static} 6 | } 7 | class LoadBalancer { 8 | - id : int {static} 9 | - lastServedId : int {static} 10 | - servers : List {static} 11 | + LoadBalancer() 12 | + addServer(server : Server) 13 | + getLastServedId() : int {static} 14 | + getNoOfServers() : int 15 | + serverRequest(request : Request) 16 | } 17 | class Request { 18 | + value : String 19 | + Request(value : String) 20 | } 21 | class Server { 22 | - LOGGER : Logger {static} 23 | + host : String 24 | + id : int 25 | + port : int 26 | + Server(host : String, port : int, id : int) 27 | + getHost() : String 28 | + getPort() : int 29 | + serve(request : Request) 30 | } 31 | } 32 | LoadBalancer --> "-servers" Server 33 | @enduml -------------------------------------------------------------------------------- /object-pool/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: pattern 3 | title: Object Pool 4 | folder: object-pool 5 | permalink: /patterns/object-pool/ 6 | pumlid: JSV94SCm2030Lk829Fxf1cF6bWU1XYDkFtdcjxiD9Qc3o-LrPQvu0pW-_HnvrLx1JgR9cfrimf1wCD7XnW-sWsESsXPcicl0nFW1RB-PiYqp0KxwVo-VVTMKBm00 7 | categories: Creational 8 | tags: 9 | - Java 10 | - Difficulty-Beginner 11 | - Performance 12 | --- 13 | 14 | ## Intent 15 | When objects are expensive to create and they are needed only for 16 | short periods of time it is advantageous to utilize the Object Pool pattern. 17 | The Object Pool provides a cache for instantiated objects tracking which ones 18 | are in use and which are available. 19 | 20 | ![alt text](./etc/object-pool.png "Object Pool") 21 | 22 | ## Applicability 23 | Use the Object Pool pattern when 24 | 25 | * the objects are expensive to create (allocation cost) 26 | * you need a large number of short-lived objects (memory fragmentation) 27 | -------------------------------------------------------------------------------- /double-dispatch/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: pattern 3 | title: Double Dispatch 4 | folder: double-dispatch 5 | permalink: /patterns/double-dispatch/ 6 | pumlid: NSbB3iCW303HgpG70Ezx6yTOWSeOv4zp_MRTtUZDCPGa6wV9gqTiVmCOtlKQqVDCPwEbmHgLreGXUMEWmGU_M1hxkBHiZ61JXud-1BILft1fmvz37JZetshQh3kd_000 7 | categories: Other 8 | tags: 9 | - Java 10 | - Difficulty-Intermediate 11 | - Idiom 12 | --- 13 | 14 | ## Intent 15 | Double Dispatch pattern is a way to create maintainable dynamic 16 | behavior based on receiver and parameter types. 17 | 18 | ![alt text](./etc/double-dispatch.png "Double Dispatch") 19 | 20 | ## Applicability 21 | Use the Double Dispatch pattern when 22 | 23 | * the dynamic behavior is not defined only based on receiving object's type but also on the receiving method's parameter type. 24 | 25 | ## Real world examples 26 | 27 | * [ObjectOutputStream](https://docs.oracle.com/javase/8/docs/api/java/io/ObjectOutputStream.html) 28 | -------------------------------------------------------------------------------- /producer-consumer/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: pattern 3 | title: Producer Consumer 4 | folder: producer-consumer 5 | permalink: /patterns/producer-consumer/ 6 | pumlid: PSjB3iCW303HgxG70Ezx6zTO2HKso9_a-c7VtUX9y-vA8nkdZTSPiVm3O7ZNeyUPttGscXgiKMaAz94t1XhyyCBIsFkXPM44cpe8-WvODbiIMzcdfspXe7-jQL9NodW0 7 | categories: Concurrency 8 | tags: 9 | - Java 10 | - Difficulty-Intermediate 11 | - I/O 12 | - Reactive 13 | --- 14 | 15 | ## Intent 16 | Producer Consumer Design pattern is a classic concurrency pattern which reduces 17 | coupling between Producer and Consumer by separating Identification of work with Execution of 18 | Work. 19 | 20 | ![alt text](./etc/producer-consumer.png "Producer Consumer") 21 | 22 | ## Applicability 23 | Use the Producer Consumer idiom when 24 | 25 | * decouple system by separate work in two process produce and consume. 26 | * addresses the issue of different timing require to produce work or consuming work 27 | -------------------------------------------------------------------------------- /adapter/etc/adapter.urm.puml: -------------------------------------------------------------------------------- 1 | @startuml 2 | package com.iluwatar.adapter { 3 | class App { 4 | + App() 5 | + main(args : String[]) {static} 6 | } 7 | class BattleFishingBoat { 8 | - LOGGER : Logger {static} 9 | - boat : FishingBoat 10 | + BattleFishingBoat() 11 | + fire() 12 | + move() 13 | } 14 | interface BattleShip { 15 | + fire() {abstract} 16 | + move() {abstract} 17 | } 18 | class Captain { 19 | - battleship : BattleShip 20 | + Captain() 21 | + Captain(battleship : BattleShip) 22 | + fire() 23 | + move() 24 | + setBattleship(battleship : BattleShip) 25 | } 26 | class FishingBoat { 27 | - LOGGER : Logger {static} 28 | + FishingBoat() 29 | + fish() 30 | + sail() 31 | } 32 | } 33 | BattleFishingBoat --> "-boat" FishingBoat 34 | Captain --> "-battleship" BattleShip 35 | BattleFishingBoat ..|> BattleShip 36 | Captain ..|> BattleShip 37 | @enduml -------------------------------------------------------------------------------- /half-sync-half-async/etc/half-sync-half-async.urm.puml: -------------------------------------------------------------------------------- 1 | @startuml 2 | package com.iluwatar.halfsynchalfasync { 3 | class App { 4 | - LOGGER : Logger {static} 5 | + App() 6 | - ap(i : long) : long {static} 7 | + main(args : String[]) {static} 8 | } 9 | ~class ArithmeticSumTask { 10 | - n : long 11 | + ArithmeticSumTask(n : long) 12 | + call() : Long 13 | + onError(throwable : Throwable) 14 | + onPostCall(result : Long) 15 | + onPreCall() 16 | } 17 | interface AsyncTask { 18 | + call() : O {abstract} 19 | + onError(Throwable) {abstract} 20 | + onPostCall(O) {abstract} 21 | + onPreCall() {abstract} 22 | } 23 | class AsynchronousService { 24 | - service : ExecutorService 25 | + AsynchronousService(workQueue : BlockingQueue) 26 | + execute(task : AsyncTask) 27 | } 28 | } 29 | ArithmeticSumTask ..+ App 30 | ArithmeticSumTask ..|> AsyncTask 31 | @enduml -------------------------------------------------------------------------------- /naked-objects/webapp/src/main/webapp/css/application.css: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | -------------------------------------------------------------------------------- /tls/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: pattern 3 | title: Thread Local Storage 4 | folder: tls 5 | permalink: /patterns/tls/ 6 | pumlid: 7 | categories: Concurrency 8 | tags: 9 | - Java 10 | - Difficulty-Intermediate 11 | --- 12 | 13 | ## Intent 14 | Securing variables global to a thread against being spoiled by other threads. That is needed if you use class variables or static variables in your Callable object or Runnable object that are not read-only. 15 | 16 | ![alt text](./etc/tls.png "Thread Local Storage") 17 | 18 | ## Applicability 19 | Use the Thread Local Storage in any of the following situations 20 | 21 | * when you use class variables in your Callable / Runnalbe object that are not read-only and you use the same Callable instance in more than one thread running in parallel 22 | * when you use static variables in your Callable / Runnable object that are not read-only and more than one instances of the Callable / Runnalbe may run in parallel threads. 23 | -------------------------------------------------------------------------------- /data-mapper/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: pattern 3 | title: Data Mapper 4 | folder: data-mapper 5 | permalink: /patterns/data-mapper/ 6 | pumlid: JShB3OGm303HLg20nFVjnYGM1CN6ycTfVtFSsnjfzY5jPgUqkLqHwXy0mxUU8wuyqidQ8q4IjJqCO-QBWGOtVh5qyd5AKOmW4mT6Nu2-ZiAekapH_hkcSTNa-GC0 7 | categories: Persistence Tier 8 | tags: 9 | - Java 10 | - Difficulty-Beginner 11 | --- 12 | 13 | ## Intent 14 | A layer of mappers that moves data between objects and a database while keeping them independent of each other and the mapper itself 15 | 16 | ![alt text](./etc/data-mapper.png "Data Mapper") 17 | 18 | ## Applicability 19 | Use the Data Mapper in any of the following situations 20 | 21 | * when you want to decouple data objects from DB access layer 22 | * when you want to write multiple data retrieval/persistence implementations 23 | 24 | ## Credits 25 | 26 | * [Data Mapper](http://richard.jp.leguen.ca/tutoring/soen343-f2010/tutorials/implementing-data-mapper/) 27 | -------------------------------------------------------------------------------- /event-queue/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: pattern 3 | title: Event Queue 4 | folder: event-queue 5 | permalink: /patterns/event-queue/ 6 | categories: Concurrency 7 | tags: 8 | - Java 9 | - Difficulty Intermediate 10 | - Queue 11 | --- 12 | 13 | ## Intent 14 | Event Queue is a good pattern if You have a limited accesibility resource (for example: 15 | Audio or Database), but You need to handle all the requests that want to use that. 16 | It puts all the requests in a queue and process them asynchronously. 17 | Gives the resource for the event when it is the next in the queue and in same time 18 | removes it from the queue. 19 | 20 | ![alt text](./etc/model.png "Event Queue") 21 | 22 | ## Applicability 23 | Use the Event Queue pattern when 24 | 25 | * You have a limited accesibility resource and the asynchronous process is acceptable to reach that 26 | 27 | ## Credits 28 | 29 | * [Mihaly Kuprivecz - Event Queue] (http://gameprogrammingpatterns.com/event-queue.html) 30 | -------------------------------------------------------------------------------- /mutex/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: pattern 3 | title: Mutex 4 | folder: mutex 5 | permalink: /patterns/mutex/ 6 | pumlid: 9SR13OCm30NGLSe0n7UsCS62LB69x6zWV2hrdTxKhFRS9Br_3c34GkHybxtXo3L3l9u6CPHwAhMUDuETldpnl4cqtUR1WBW5ASSlf0bvI53_A-bQHcf_0G00 7 | categories: Concurrency 8 | tags: 9 | - Java 10 | - Difficulty-Intermediate 11 | --- 12 | 13 | ## Also known as 14 | Mutual Exclusion Lock 15 | Binary Semaphore 16 | 17 | ## Intent 18 | Create a lock which only allows a single thread to access a resource at any one instant. 19 | 20 | ![alt text](./etc/mutex.png "Mutex") 21 | 22 | ## Applicability 23 | Use a Mutex when 24 | 25 | * you need to prevent two threads accessing a critical section at the same time 26 | * concurrent access to a resource could lead to a race condition 27 | 28 | ## Credits 29 | 30 | * [Lock (computer science)] (http://en.wikipedia.org/wiki/Lock_(computer_science)) 31 | * [Semaphores] (http://tutorials.jenkov.com/java-concurrency/semaphores.html) 32 | -------------------------------------------------------------------------------- /thread-pool/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: pattern 3 | title: Thread Pool 4 | folder: thread-pool 5 | permalink: /patterns/thread-pool/ 6 | pumlid: JSV14SCW30J0Lk82GFzq8uF6a1624IUx_UIPt-xHhMXK2TTN0zP-4pa_-UfeSSOMBzCWXbpceAxnCDZfmpUdAhjVbXO3uhPfyFw1q5oufZMdag3yFuUFl6Be5m00 7 | categories: Concurrency 8 | tags: 9 | - Java 10 | - Difficulty-Intermediate 11 | - Performance 12 | --- 13 | 14 | ## Intent 15 | It is often the case that tasks to be executed are short-lived and 16 | the number of tasks is large. Creating a new thread for each task would make 17 | the system spend more time creating and destroying the threads than executing 18 | the actual tasks. Thread Pool solves this problem by reusing existing threads 19 | and eliminating the latency of creating new threads. 20 | 21 | ![alt text](./etc/thread-pool.png "Thread Pool") 22 | 23 | ## Applicability 24 | Use the Thread Pool pattern when 25 | 26 | * you have a large number of short-lived tasks to be executed in parallel 27 | -------------------------------------------------------------------------------- /model-view-presenter/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: pattern 3 | title: Model-View-Presenter 4 | folder: model-view-presenter 5 | permalink: /patterns/model-view-presenter/ 6 | pumlid: ROlR3SGW3C1MkGu0-RzjKeXQJWcWFChwPO3xispvQBrmL0hbp-q-xGkWkFBL_8upZBICxjGzbo7GE1OwAlpmmLJ9sjNJH7VIRY1e6q169KvFevMcakrtI_BoD-HGoJE4Nm00 7 | categories: Presentation Tier 8 | tags: 9 | - Java 10 | - Difficulty-Intermediate 11 | --- 12 | 13 | ## Intent 14 | Apply a "Separation of Concerns" principle in a way that allows 15 | developers to build and test user interfaces. 16 | 17 | ![alt text](./etc/model-view-presenter_1.png "Model-View-Presenter") 18 | 19 | ## Applicability 20 | Use the Model-View-Presenter in any of the following 21 | situations 22 | 23 | * when you want to improve the "Separation of Concerns" principle in presentation logic 24 | * when a user interface development and testing is necessary. 25 | 26 | ## Real world examples 27 | 28 | * [MVP4J](https://github.com/amineoualialami/mvp4j) 29 | -------------------------------------------------------------------------------- /naked-objects/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: pattern 3 | title: Naked Objects 4 | folder: naked-objects 5 | permalink: /patterns/naked-objects/ 6 | categories: Architectural 7 | tags: 8 | - Java 9 | - Difficulty-Expert 10 | --- 11 | 12 | ## Intent 13 | The Naked Objects architectural pattern is well suited for rapid 14 | prototyping. Using the pattern, you only need to write the domain objects, 15 | everything else is autogenerated by the framework. 16 | 17 | ![alt text](./etc/naked-objects.png "Naked Objects") 18 | 19 | ## Applicability 20 | Use the Naked Objects pattern when 21 | 22 | * you are prototyping and need fast development cycle 23 | * an autogenerated user interface is good enough 24 | * you want to automatically publish the domain as REST services 25 | 26 | ## Real world examples 27 | 28 | * [Apache Isis](https://isis.apache.org/) 29 | 30 | ## Credits 31 | 32 | * [Richard Pawson - Naked Objects](https://isis.apache.org/resources/thesis/Pawson-Naked-Objects-thesis.pdf) 33 | -------------------------------------------------------------------------------- /thread-pool/etc/thread-pool.urm.puml: -------------------------------------------------------------------------------- 1 | @startuml 2 | package com.iluwatar.threadpool { 3 | class App { 4 | - LOGGER : Logger {static} 5 | + App() 6 | + main(args : String[]) {static} 7 | } 8 | class CoffeeMakingTask { 9 | - TIME_PER_CUP : int {static} 10 | + CoffeeMakingTask(numCups : int) 11 | + toString() : String 12 | } 13 | class PotatoPeelingTask { 14 | - TIME_PER_POTATO : int {static} 15 | + PotatoPeelingTask(numPotatoes : int) 16 | + toString() : String 17 | } 18 | abstract class Task { 19 | - ID_GENERATOR : AtomicInteger {static} 20 | - id : int 21 | - timeMs : int 22 | + Task(timeMs : int) 23 | + getId() : int 24 | + getTimeMs() : int 25 | + toString() : String 26 | } 27 | class Worker { 28 | - LOGGER : Logger {static} 29 | - task : Task 30 | + Worker(task : Task) 31 | + run() 32 | } 33 | } 34 | Worker --> "-task" Task 35 | CoffeeMakingTask --|> Task 36 | PotatoPeelingTask --|> Task 37 | @enduml -------------------------------------------------------------------------------- /servant/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: pattern 3 | title: Servant 4 | folder: servant 5 | permalink: /patterns/servant/ 6 | pumlid: DSkn4O0m20NGLNG0G-ys63cDbv0SV7HzRUnUy-QYkSOkONKwWU4haV6JZe8pjd2nt1MYIBatAZKU1XjTVFEoYvT3by60c3erzW_qdPiL9CY_KrXB8rfz0G00 7 | categories: Structural 8 | tags: 9 | - Java 10 | - Difficulty-Beginner 11 | --- 12 | 13 | ## Intent 14 | Servant is used for providing some behavior to a group of classes. 15 | Instead of defining that behavior in each class - or when we cannot factor out 16 | this behavior in the common parent class - it is defined once in the Servant. 17 | 18 | ![alt text](./etc/servant-pattern.png "Servant") 19 | 20 | ## Applicability 21 | Use the Servant pattern when 22 | 23 | * when we want some objects to perform a common action and don't want to define this action as a method in every class. 24 | 25 | ## Credits 26 | * [Let's Modify the Objects-First Approach into Design-Patterns-First](http://edu.pecinovsky.cz/papers/2006_ITiCSE_Design_Patterns_First.pdf) 27 | -------------------------------------------------------------------------------- /state/etc/state.urm.puml: -------------------------------------------------------------------------------- 1 | @startuml 2 | package com.iluwatar.state { 3 | class AngryState { 4 | - LOGGER : Logger {static} 5 | - mammoth : Mammoth 6 | + AngryState(mammoth : Mammoth) 7 | + observe() 8 | + onEnterState() 9 | } 10 | class App { 11 | + App() 12 | + main(args : String[]) {static} 13 | } 14 | class Mammoth { 15 | - state : State 16 | + Mammoth() 17 | - changeStateTo(newState : State) 18 | + observe() 19 | + timePasses() 20 | + toString() : String 21 | } 22 | class PeacefulState { 23 | - LOGGER : Logger {static} 24 | - mammoth : Mammoth 25 | + PeacefulState(mammoth : Mammoth) 26 | + observe() 27 | + onEnterState() 28 | } 29 | interface State { 30 | + observe() {abstract} 31 | + onEnterState() {abstract} 32 | } 33 | } 34 | PeacefulState --> "-mammoth" Mammoth 35 | AngryState --> "-mammoth" Mammoth 36 | Mammoth --> "-state" State 37 | AngryState ..|> State 38 | PeacefulState ..|> State 39 | @enduml -------------------------------------------------------------------------------- /factory-kit/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: pattern 3 | title: Factory Kit 4 | folder: factory-kit 5 | permalink: /patterns/factory-kit/ 6 | pumlid: JST15i8m20N0g-W14lRU1YcsQ4BooCS-RwzBTpDNSscvQKQx7C1SDwBWi-w68--vD6Gur55bTBAM9uE3dlpcikcotSjaGCCNTLu_q8C58pxbPI25_Bzcz3gpjoy0 7 | categories: Creational 8 | tags: 9 | - Java 10 | - Difficulty-Beginner 11 | - Functional 12 | --- 13 | 14 | ## Intent 15 | Define a factory of immutable content with separated builder and factory interfaces. 16 | 17 | ![alt text](./etc/factory-kit.png "Factory Kit") 18 | 19 | ## Applicability 20 | Use the Factory Kit pattern when 21 | 22 | * a class can't anticipate the class of objects it must create 23 | * you just want a new instance of a custom builder instead of the global one 24 | * you explicitly want to define types of objects, that factory can build 25 | * you want a separated builder and creator interface 26 | 27 | ## Credits 28 | 29 | * [Design Pattern Reloaded by Remi Forax: ](https://www.youtube.com/watch?v=-k2X7guaArU) 30 | -------------------------------------------------------------------------------- /tolerant-reader/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: pattern 3 | title: Tolerant Reader 4 | folder: tolerant-reader 5 | permalink: /patterns/tolerant-reader/ 6 | pumlid: NSZ14SCm20NHLf829ExfXaYChGn26lZ4xSVdtFRjSrZJx9AkZnFOyI9olkenSEOxGxmjWnXgMvE6viLWfmz_kNI9SLZP38XRqEIuWx1Kd0t5XVjjGVj_DNtMdLD_ 7 | categories: Integration 8 | tags: 9 | - Java 10 | - Difficulty-Beginner 11 | --- 12 | 13 | ## Intent 14 | Tolerant Reader is an integration pattern that helps creating 15 | robust communication systems. The idea is to be as tolerant as possible when 16 | reading data from another service. This way, when the communication schema 17 | changes, the readers must not break. 18 | 19 | ![alt text](./etc/tolerant-reader.png "Tolerant Reader") 20 | 21 | ## Applicability 22 | Use the Tolerant Reader pattern when 23 | 24 | * the communication schema can evolve and change and yet the receiving side should not break 25 | 26 | ## Credits 27 | 28 | * [Martin Fowler - Tolerant Reader](http://martinfowler.com/bliki/TolerantReader.html) 29 | -------------------------------------------------------------------------------- /decorator/etc/decorator.urm.puml: -------------------------------------------------------------------------------- 1 | @startuml 2 | package com.iluwatar.decorator { 3 | class App { 4 | - LOGGER : Logger {static} 5 | + App() 6 | + main(args : String[]) {static} 7 | } 8 | class ClubbedTroll { 9 | - LOGGER : Logger {static} 10 | + ClubbedTroll(decorated : Troll) 11 | + attack() 12 | + getAttackPower() : int 13 | } 14 | class SimpleTroll { 15 | - LOGGER : Logger {static} 16 | + SimpleTroll() 17 | + attack() 18 | + fleeBattle() 19 | + getAttackPower() : int 20 | } 21 | interface Troll { 22 | + attack() {abstract} 23 | + fleeBattle() {abstract} 24 | + getAttackPower() : int {abstract} 25 | } 26 | class TrollDecorator { 27 | - decorated : Troll 28 | + TrollDecorator(decorated : Troll) 29 | + attack() 30 | + fleeBattle() 31 | + getAttackPower() : int 32 | } 33 | } 34 | TrollDecorator --> "-decorated" Troll 35 | ClubbedTroll --|> TrollDecorator 36 | SimpleTroll ..|> Troll 37 | TrollDecorator ..|> Troll 38 | @enduml -------------------------------------------------------------------------------- /naked-objects/.gitattributes: -------------------------------------------------------------------------------- 1 | # 2 | # 3 | # text files are normalized (convert crlf => lf) 4 | # binary files are not normalized (binary is a macro for -text -diff) 5 | # 6 | # 7 | 8 | 9 | # Unless otherwise stated, assume text 10 | 11 | * text=auto 12 | 13 | 14 | *.java text diff=java 15 | *.html text diff=html 16 | *.xhtml text diff=html 17 | *.xml text 18 | *.txt text 19 | 20 | 21 | *.jar binary 22 | *.so binary 23 | *.dll binary 24 | 25 | # images 26 | *.jpg binary 27 | *.jpeg binary 28 | *.png binary 29 | *.pdn binary 30 | *.pdn binary 31 | 32 | 33 | *.cs text diff=csharp 34 | 35 | *.sln merge=union 36 | *.csproj merge=union 37 | *.vbproj merge=union 38 | *.fsproj merge=union 39 | *.dbproj merge=union 40 | 41 | *.doc diff=astextplain 42 | *.DOC diff=astextplain 43 | *.docx diff=astextplain 44 | *.DOCX diff=astextplain 45 | *.dot diff=astextplain 46 | *.DOT diff=astextplain 47 | *.pdf diff=astextplain 48 | *.PDF diff=astextplain 49 | *.rtf diff=astextplain 50 | *.RTF diff=astextplain 51 | 52 | -------------------------------------------------------------------------------- /marker/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: pattern 3 | title: Marker Interface 4 | folder: marker 5 | permalink: /patterns/marker/ 6 | categories: Design 7 | tags: 8 | - Java 9 | - Difficulty-Beginner 10 | --- 11 | 12 | ## Intent 13 | Using empty interfaces as markers to distinguish special treated objects. 14 | 15 | ![alt text](./etc/MarkerDiagram.png "Marker Interface") 16 | 17 | ## Applicability 18 | Use the Marker Interface pattern when 19 | 20 | * you want to identify the special objects from normal objects (to treat them differently) 21 | * you want to mark that some object is available for certain sort of operations 22 | 23 | ## Real world examples 24 | 25 | * [javase.8.docs.api.java.io.Serializable](https://docs.oracle.com/javase/8/docs/api/java/io/Serializable.html) 26 | * [javase.8.docs.api.java.lang.Cloneable](https://docs.oracle.com/javase/8/docs/api/java/lang/Cloneable.html) 27 | 28 | ## Credits 29 | 30 | * [Effective Java 2nd Edition by Joshua Bloch](https://www.amazon.com/Effective-Java-2nd-Joshua-Bloch/dp/0321356683) 31 | -------------------------------------------------------------------------------- /producer-consumer/etc/producer-consumer.urm.puml: -------------------------------------------------------------------------------- 1 | @startuml 2 | package com.iluwatar.producer.consumer { 3 | class App { 4 | - LOGGER : Logger {static} 5 | + App() 6 | + main(args : String[]) {static} 7 | } 8 | class Consumer { 9 | - LOGGER : Logger {static} 10 | - name : String 11 | - queue : ItemQueue 12 | + Consumer(name : String, queue : ItemQueue) 13 | + consume() 14 | } 15 | class Item { 16 | - id : int 17 | - producer : String 18 | + Item(producer : String, id : int) 19 | + getId() : int 20 | + getProducer() : String 21 | } 22 | class ItemQueue { 23 | - queue : BlockingQueue 24 | + ItemQueue() 25 | + put(item : Item) 26 | + take() : Item 27 | } 28 | class Producer { 29 | - itemId : int 30 | - name : String 31 | - queue : ItemQueue 32 | + Producer(name : String, queue : ItemQueue) 33 | + produce() 34 | } 35 | } 36 | Consumer --> "-queue" ItemQueue 37 | Producer --> "-queue" ItemQueue 38 | ItemQueue --> "-queue" Item 39 | @enduml -------------------------------------------------------------------------------- /mute-idiom/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: pattern 3 | title: Mute Idiom 4 | folder: mute-idiom 5 | permalink: /patterns/mute-idiom/ 6 | pumlid: JSf13iCm20NHgxG7iDdtDjH62PKX5luarq-MtSsJvgtUHdR96AyTcEj357pLJR7dDvT4EnpYgEqmqf4NWuD-V7BfidJpCXcGy4N6wmcoX1Jj-lo2ziUQONMcZHi0 7 | categories: Other 8 | tags: 9 | - Java 10 | - Difficulty-Beginner 11 | - Idiom 12 | --- 13 | 14 | ## Intent 15 | Provide a template to suppress any exceptions that either are declared but cannot occur or should only be logged; 16 | while executing some business logic. The template removes the need to write repeated `try-catch` blocks. 17 | 18 | 19 | ![alt text](./etc/mute-idiom.png "Mute Idiom") 20 | 21 | ## Applicability 22 | Use this idiom when 23 | 24 | * an API declares some exception but can never throw that exception eg. ByteArrayOutputStream bulk write method. 25 | * you need to suppress some exception just by logging it, such as closing a resource. 26 | 27 | ## Credits 28 | 29 | * [JOOQ: Mute Design Pattern](http://blog.jooq.org/2016/02/18/the-mute-design-pattern/) 30 | -------------------------------------------------------------------------------- /lazy-loading/etc/lazy-loading.urm.puml: -------------------------------------------------------------------------------- 1 | @startuml 2 | package com.iluwatar.lazy.loading { 3 | class App { 4 | - LOGGER : Logger {static} 5 | + App() 6 | + main(args : String[]) {static} 7 | } 8 | class Heavy { 9 | - LOGGER : Logger {static} 10 | + Heavy() 11 | } 12 | class HolderNaive { 13 | - LOGGER : Logger {static} 14 | - heavy : Heavy 15 | + HolderNaive() 16 | + getHeavy() : Heavy 17 | } 18 | class HolderThreadSafe { 19 | - LOGGER : Logger {static} 20 | - heavy : Heavy 21 | + HolderThreadSafe() 22 | + getHeavy() : Heavy 23 | } 24 | class Java8Holder { 25 | - LOGGER : Logger {static} 26 | - heavy : Supplier 27 | + Java8Holder() 28 | - createAndCacheHeavy() : Heavy 29 | + getHeavy() : Heavy 30 | } 31 | ~class HeavyFactory { 32 | - heavyInstance : Heavy 33 | ~ HeavyFactory() 34 | + get() : Heavy 35 | } 36 | } 37 | HolderThreadSafe --> "-heavy" Heavy 38 | HolderNaive --> "-heavy" Heavy 39 | HeavyFactory --> "-heavyInstance" Heavy 40 | @enduml -------------------------------------------------------------------------------- /layers/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: pattern 3 | title: Layers 4 | folder: layers 5 | permalink: /patterns/layers/ 6 | pumlid: BSR13OCm30NGLSe0n7UsCS62L8w9x6yGszD3t-bDpQhc9kdwEO0H2v7pNVQ68zSCyNeQn53gsQbftWns-lB5yoRHTfi70-8Mr3b-8UL7F4XG_otflOpi-W80 7 | pumlformat: svg 8 | categories: Architectural 9 | tags: 10 | - Java 11 | - Difficulty-Intermediate 12 | - Spring 13 | --- 14 | 15 | ## Intent 16 | Layers is an architectural style where software responsibilities are 17 | divided among the different layers of the application. 18 | 19 | ![alt text](./etc/layers.png "Layers") 20 | 21 | ## Applicability 22 | Use the Layers architecture when 23 | 24 | * you want clearly divide software responsibilities into differents parts of the program 25 | * you want to prevent a change from propagating throughout the application 26 | * you want to make your application more maintainable and testable 27 | 28 | ## Credits 29 | 30 | * [Pattern Oriented Software Architecture Vol I-V](http://www.amazon.com/Pattern-Oriented-Software-Architecture-Volume-Patterns/dp/0471958697) 31 | -------------------------------------------------------------------------------- /monad/etc/monad.urm.puml: -------------------------------------------------------------------------------- 1 | @startuml 2 | package com.iluwatar.monad { 3 | class App { 4 | - LOGGER : Logger {static} 5 | + App() 6 | + main(args : String[]) {static} 7 | } 8 | enum Sex { 9 | + FEMALE {static} 10 | + MALE {static} 11 | + valueOf(name : String) : Sex {static} 12 | + values() : Sex[] {static} 13 | } 14 | class User { 15 | - age : int 16 | - email : String 17 | - name : String 18 | - sex : Sex 19 | + User(name : String, age : int, sex : Sex, email : String) 20 | + getAge() : int 21 | + getEmail() : String 22 | + getName() : String 23 | + getSex() : Sex 24 | } 25 | class Validator { 26 | - exceptions : List 27 | - t : T 28 | - Validator(t : T) 29 | + get() : T 30 | + of(t : T) : Validator {static} 31 | + validate(projection : Function, validation : Predicate, message : String) : Validator 32 | + validate(validation : Predicate, message : String) : Validator 33 | } 34 | } 35 | User --> "-sex" Sex 36 | @enduml -------------------------------------------------------------------------------- /callback/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: pattern 3 | title: Callback 4 | folder: callback 5 | permalink: /patterns/callback/ 6 | pumlid: FSVB4S8m30N0Lg20M7UwUL4qYOciUFGXxSE9s-wp6sjjKgwF8tF6YyXnjxtdKMk5E5-MOjdu6jIrRYIStlXWsIJwRij4fhW53SGFn51TmIT9yZ-jVBHPGxy0 7 | categories: Other 8 | tags: 9 | - Java 10 | - Difficulty-Beginner 11 | - Functional 12 | - Idiom 13 | --- 14 | 15 | ## Intent 16 | Callback is a piece of executable code that is passed as an 17 | argument to other code, which is expected to call back (execute) the argument 18 | at some convenient time. 19 | 20 | ![alt text](./etc/callback.png "Callback") 21 | 22 | ## Applicability 23 | Use the Callback pattern when 24 | 25 | * when some arbitrary synchronous or asynchronous action must be performed after execution of some defined activity. 26 | 27 | ## Real world examples 28 | 29 | * [CyclicBarrier](http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/CyclicBarrier.html#CyclicBarrier%28int,%20java.lang.Runnable%29) constructor can accept callback that will be triggered every time when barrier is tripped. 30 | -------------------------------------------------------------------------------- /delegation/etc/delegation.urm.puml: -------------------------------------------------------------------------------- 1 | @startuml 2 | package com.iluwatar.delegation.simple.printers { 3 | class CanonPrinter { 4 | - LOGGER : Logger {static} 5 | + CanonPrinter() 6 | + print(message : String) 7 | } 8 | class EpsonPrinter { 9 | - LOGGER : Logger {static} 10 | + EpsonPrinter() 11 | + print(message : String) 12 | } 13 | class HpPrinter { 14 | - LOGGER : Logger {static} 15 | + HpPrinter() 16 | + print(message : String) 17 | } 18 | } 19 | package com.iluwatar.delegation.simple { 20 | class App { 21 | + MESSAGE_TO_PRINT : String {static} 22 | + App() 23 | + main(args : String[]) {static} 24 | } 25 | interface Printer { 26 | + print(String) {abstract} 27 | } 28 | class PrinterController { 29 | - printer : Printer 30 | + PrinterController(printer : Printer) 31 | + print(message : String) 32 | } 33 | } 34 | PrinterController --> "-printer" Printer 35 | PrinterController ..|> Printer 36 | CanonPrinter ..|> Printer 37 | EpsonPrinter ..|> Printer 38 | HpPrinter ..|> Printer 39 | @enduml -------------------------------------------------------------------------------- /strategy/etc/strategy.urm.puml: -------------------------------------------------------------------------------- 1 | @startuml 2 | package com.iluwatar.strategy { 3 | class App { 4 | - LOGGER : Logger {static} 5 | + App() 6 | + main(args : String[]) {static} 7 | } 8 | class DragonSlayer { 9 | - strategy : DragonSlayingStrategy 10 | + DragonSlayer(strategy : DragonSlayingStrategy) 11 | + changeStrategy(strategy : DragonSlayingStrategy) 12 | + goToBattle() 13 | } 14 | interface DragonSlayingStrategy { 15 | + execute() {abstract} 16 | } 17 | class MeleeStrategy { 18 | - LOGGER : Logger {static} 19 | + MeleeStrategy() 20 | + execute() 21 | } 22 | class ProjectileStrategy { 23 | - LOGGER : Logger {static} 24 | + ProjectileStrategy() 25 | + execute() 26 | } 27 | class SpellStrategy { 28 | - LOGGER : Logger {static} 29 | + SpellStrategy() 30 | + execute() 31 | } 32 | } 33 | DragonSlayer --> "-strategy" DragonSlayingStrategy 34 | MeleeStrategy ..|> DragonSlayingStrategy 35 | ProjectileStrategy ..|> DragonSlayingStrategy 36 | SpellStrategy ..|> DragonSlayingStrategy 37 | @enduml -------------------------------------------------------------------------------- /flux/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: pattern 3 | title: Flux 4 | folder: flux 5 | permalink: /patterns/flux/ 6 | pumlid: 7SP14eCm20NGg-W13FlU1YFLE0GpyAazVZk-rPkRLSrDqdKwW14l8kUxx0r7hXdYzJA8eTIhKzEy6UnqyeUNJQBjjWm6n2seS_n3Ryql2UgJajxBoAu_ 7 | categories: Presentation Tier 8 | tags: 9 | - Java 10 | - Difficulty-Intermediate 11 | --- 12 | 13 | ## Intent 14 | Flux eschews MVC in favor of a unidirectional data flow. When a 15 | user interacts with a view, the view propagates an action through a central 16 | dispatcher, to the various stores that hold the application's data and business 17 | logic, which updates all of the views that are affected. 18 | 19 | ![alt text](./etc/flux.png "Flux") 20 | 21 | ## Applicability 22 | Use the Flux pattern when 23 | 24 | * you want to focus on creating explicit and understandable update paths for your application's data, which makes tracing changes during development simpler and makes bugs easier to track down and fix. 25 | 26 | ## Credits 27 | 28 | * [Flux - Application architecture for building user interfaces](http://facebook.github.io/flux/) 29 | -------------------------------------------------------------------------------- /delegation/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: pattern 3 | title: Delegation 4 | folder: delegation 5 | permalink: /patterns/delegation/ 6 | pumlid: JSV14GCX20NGLf82LkxfXbN69OFeu2VRVdBCxRsdUhLiac6F2rZxHHHybwwuyimjKQT37ANEGMfvCpZepHy-ccpjVYm697pJuFq3DJ7f39rEWlhNaZ7Aoc5V 7 | categories: Behavioral 8 | tags: 9 | - Java 10 | - Difficulty-Beginner 11 | --- 12 | 13 | ## Also known as 14 | Proxy Pattern 15 | 16 | ## Intent 17 | It is a technique where an object expresses certain behavior to the outside but in 18 | reality delegates responsibility for implementing that behaviour to an associated object. 19 | 20 | ![alt text](./etc/delegation.png "Delegate") 21 | 22 | ## Applicability 23 | Use the Delegate pattern in order to achieve the following 24 | 25 | * Reduce the coupling of methods to their class 26 | * Components that behave identically, but realize that this situation can change in the future. 27 | 28 | ## Credits 29 | 30 | * [Delegate Pattern: Wikipedia ](https://en.wikipedia.org/wiki/Delegation_pattern) 31 | * [Proxy Pattern: Wikipedia ](https://en.wikipedia.org/wiki/Proxy_pattern) 32 | -------------------------------------------------------------------------------- /api-gateway/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: pattern 3 | title: API Gateway 4 | folder: api-gateway 5 | permalink: /patterns/api-gateway/ 6 | pumlid: JSox3SCm303HLP819FRUXg49cO542_nOyFPncUvUSszHwhbpMdyT4TCt0CDLcyIHdtGsEZLOez8vG7ek33JuueLbPvUcPM84cpeCz2S0fvI6mGjluA1_b-Tt2N5D6tNcw3y0 7 | categories: Architectural 8 | tags: 9 | - Java 10 | - Difficulty-Intermediate 11 | - Spring 12 | --- 13 | 14 | ## Intent 15 | 16 | Aggregate calls to microservices in a single location: the API Gateway. The user makes a single 17 | call to the API Gateway, and the API Gateway then calls each relevant microservice. 18 | 19 | ![alt text](./etc/api-gateway.png "API Gateway") 20 | 21 | ## Applicability 22 | 23 | Use the API Gateway pattern when 24 | 25 | * you're also using the Microservices pattern and need a single point of aggregation for your 26 | microservice calls 27 | 28 | ## Credits 29 | 30 | * [microservices.io - API Gateway](http://microservices.io/patterns/apigateway.html) 31 | * [NGINX - Building Microservices: Using an API Gateway](https://www.nginx.com/blog/building-microservices-using-an-api-gateway/) 32 | -------------------------------------------------------------------------------- /private-class-data/etc/private-class-data.urm.puml: -------------------------------------------------------------------------------- 1 | @startuml 2 | package com.iluwatar.privateclassdata { 3 | class App { 4 | + App() 5 | + main(args : String[]) {static} 6 | } 7 | class ImmutableStew { 8 | - LOGGER : Logger {static} 9 | - data : StewData 10 | + ImmutableStew(numPotatoes : int, numCarrots : int, numMeat : int, numPeppers : int) 11 | + mix() 12 | } 13 | class Stew { 14 | - LOGGER : Logger {static} 15 | - numCarrots : int 16 | - numMeat : int 17 | - numPeppers : int 18 | - numPotatoes : int 19 | + Stew(numPotatoes : int, numCarrots : int, numMeat : int, numPeppers : int) 20 | + mix() 21 | + taste() 22 | } 23 | class StewData { 24 | - numCarrots : int 25 | - numMeat : int 26 | - numPeppers : int 27 | - numPotatoes : int 28 | + StewData(numPotatoes : int, numCarrots : int, numMeat : int, numPeppers : int) 29 | + getNumCarrots() : int 30 | + getNumMeat() : int 31 | + getNumPeppers() : int 32 | + getNumPotatoes() : int 33 | } 34 | } 35 | ImmutableStew --> "-data" StewData 36 | @enduml -------------------------------------------------------------------------------- /page-object/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: pattern 3 | title: Page Object 4 | folder: page-object 5 | permalink: /patterns/page-object/ 6 | categories: Testing 7 | tags: 8 | - Java 9 | - Difficulty-Intermediate 10 | --- 11 | 12 | ## Intent 13 | 14 | Page Object encapsulates the UI, hiding the underlying UI widgetry of an application (commonly a web application) and providing an application-specific API to allow the manipulation of UI components required for tests. In doing so, it allows the test class itself to focus on the test logic instead. 15 | 16 | 17 | ![alt text](./etc/page-object.png "Page Object") 18 | 19 | 20 | ## Applicability 21 | 22 | Use the Page Object pattern when 23 | 24 | * You are writing automated tests for your web application and you want to separate the UI manipulation required for the tests from the actual test logic. 25 | * Make your tests less brittle, and more readable and robust 26 | 27 | ## Credits 28 | 29 | * [Martin Fowler - PageObject](http://martinfowler.com/bliki/PageObject.html) 30 | * [Selenium - Page Objects](https://github.com/SeleniumHQ/selenium/wiki/PageObjects) 31 | -------------------------------------------------------------------------------- /execute-around/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: pattern 3 | title: Execute Around 4 | folder: execute-around 5 | permalink: /patterns/execute-around/ 6 | pumlid: NSZ14G8n20NGLhI0XBlT865suoGa0n_NylNixSsxTvEHJTF7xGHsF8YShtfqdFdCK9TbK4ELDQcFl1ZizE8tbwRH3okR0NKBcXm_a7vK4bhOLreZXVnLJPzrvnnV 7 | categories: Other 8 | tags: 9 | - Java 10 | - Difficulty-Beginner 11 | - Idiom 12 | --- 13 | 14 | ## Intent 15 | Execute Around idiom frees the user from certain actions that 16 | should always be executed before and after the business method. A good example 17 | of this is resource allocation and deallocation leaving the user to specify 18 | only what to do with the resource. 19 | 20 | ![alt text](./etc/execute-around.png "Execute Around") 21 | 22 | ## Applicability 23 | Use the Execute Around idiom when 24 | 25 | * you use an API that requires methods to be called in pairs such as open/close or allocate/deallocate. 26 | 27 | ## Credits 28 | * [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) 29 | -------------------------------------------------------------------------------- /abstract-document/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: pattern 3 | title: Abstract Document 4 | folder: abstract-document 5 | permalink: /patterns/abstract-document/ 6 | pumlid: PSjB3eCm34NHhPG599vtDyQn85L-ifzX-p3lxEf8Twj3MXGDQvyJMFubChxpKN767gucSq07iinEjSNDOACVNvoAUZr6MWoe3QVE_WRnxZ0Mf38b-hkIGlurX_MyehS7 7 | categories: Structural 8 | tags: 9 | - Java 10 | - Difficulty-Intermediate 11 | --- 12 | 13 | ## Intent 14 | Achieve flexibility of untyped languages and keep the type-safety 15 | 16 | ![alt text](./etc/abstract-document-base.png "Abstract Document Base") 17 | 18 | ![alt text](./etc/abstract-document.png "Abstract Document Traits and Domain") 19 | 20 | 21 | ## Applicability 22 | Use the Abstract Document Pattern when 23 | 24 | * there is a need to add new properties on the fly 25 | * you want a flexible way to organize domain in tree like structure 26 | * you want more loosely coupled system 27 | 28 | 29 | ## Credits 30 | 31 | * [Wikipedia: Abstract Document Pattern](https://en.wikipedia.org/wiki/Abstract_Document_Pattern) 32 | * [Martin Fowler: Dealing with properties](http://martinfowler.com/apsupp/properties.pdf) -------------------------------------------------------------------------------- /null-object/etc/null-object.urm.puml: -------------------------------------------------------------------------------- 1 | @startuml 2 | package com.iluwatar.nullobject { 3 | class App { 4 | + App() 5 | + main(args : String[]) {static} 6 | } 7 | interface Node { 8 | + getLeft() : Node {abstract} 9 | + getName() : String {abstract} 10 | + getRight() : Node {abstract} 11 | + getTreeSize() : int {abstract} 12 | + walk() {abstract} 13 | } 14 | class NodeImpl { 15 | - LOGGER : Logger {static} 16 | - left : Node 17 | - name : String 18 | - right : Node 19 | + NodeImpl(name : String, left : Node, right : Node) 20 | + getLeft() : Node 21 | + getName() : String 22 | + getRight() : Node 23 | + getTreeSize() : int 24 | + walk() 25 | } 26 | class NullNode { 27 | - instance : NullNode {static} 28 | - NullNode() 29 | + getInstance() : NullNode {static} 30 | + getLeft() : Node 31 | + getName() : String 32 | + getRight() : Node 33 | + getTreeSize() : int 34 | + walk() 35 | } 36 | } 37 | NullNode --> "-instance" NullNode 38 | NodeImpl --> "-left" Node 39 | NodeImpl ..|> Node 40 | NullNode ..|> Node 41 | @enduml -------------------------------------------------------------------------------- /data-bus/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: pattern 3 | title: Data Bus 4 | folder: data-bus 5 | permalink: /patterns/data-bus/ 6 | 7 | categories: Architectural 8 | tags: 9 | - Java 10 | - Difficulty-Intermediate 11 | --- 12 | 13 | ## Intent 14 | 15 | Allows send of messages/events between components of an application 16 | without them needing to know about each other. They only need to know 17 | about the type of the message/event being sent. 18 | 19 | ![data bus pattern uml diagram](./etc/data-bus.urm.png "Data Bus pattern") 20 | 21 | ## Applicability 22 | Use Data Bus pattern when 23 | 24 | * you want your components to decide themselves which messages/events they want to receive 25 | * you want to have many-to-many communication 26 | * you want your components to know nothing about each other 27 | 28 | ## Related Patterns 29 | Data Bus is similar to 30 | 31 | * Mediator pattern with Data Bus Members deciding for themselves if they want to accept any given message 32 | * Observer pattern but supporting many-to-many communication 33 | * Publish/Subscribe pattern with the Data Bus decoupling the publisher and the subscriber 34 | -------------------------------------------------------------------------------- /factory-kit/etc/factory-kit.urm.puml: -------------------------------------------------------------------------------- 1 | @startuml 2 | package com.iluwatar.factorykit { 3 | class App { 4 | - LOGGER : Logger {static} 5 | + App() 6 | + main(args : String[]) {static} 7 | } 8 | class Axe { 9 | + Axe() 10 | + toString() : String 11 | } 12 | class Bow { 13 | + Bow() 14 | + toString() : String 15 | } 16 | interface Builder { 17 | + add(WeaponType, Supplier) {abstract} 18 | } 19 | class Spear { 20 | + Spear() 21 | + toString() : String 22 | } 23 | class Sword { 24 | + Sword() 25 | + toString() : String 26 | } 27 | interface Weapon { 28 | } 29 | interface WeaponFactory { 30 | + create(WeaponType) : Weapon {abstract} 31 | + factory(consumer : Consumer) : WeaponFactory {static} 32 | } 33 | enum WeaponType { 34 | + AXE {static} 35 | + BOW {static} 36 | + SPEAR {static} 37 | + SWORD {static} 38 | + valueOf(name : String) : WeaponType {static} 39 | + values() : WeaponType[] {static} 40 | } 41 | } 42 | Axe ..|> Weapon 43 | Bow ..|> Weapon 44 | Spear ..|> Weapon 45 | Sword ..|> Weapon 46 | @enduml -------------------------------------------------------------------------------- /lazy-loading/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: pattern 3 | title: Lazy Loading 4 | folder: lazy-loading 5 | permalink: /patterns/lazy-loading/ 6 | pumlid: LSXB3W8X303Gg-W1e7jlqu66gIc5zED4JwzRTo_lpjeaEwN9xOpO_W0mlEhWEFD89sjBWpHgMnDOyi90WoU-i7Ho7besHf2fmqJ_0GG_xo8BE-i0YlONDMtMdLE- 7 | categories: Other 8 | tags: 9 | - Java 10 | - Difficulty-Beginner 11 | - Idiom 12 | - Performance 13 | --- 14 | 15 | ## Intent 16 | Lazy loading is a design pattern commonly used to defer 17 | initialization of an object until the point at which it is needed. It can 18 | contribute to efficiency in the program's operation if properly and 19 | appropriately used. 20 | 21 | ![alt text](./etc/lazy-loading.png "Lazy Loading") 22 | 23 | ## Applicability 24 | Use the Lazy Loading idiom when 25 | 26 | * eager loading is expensive or the object to be loaded might not be needed at all 27 | 28 | ## Real world examples 29 | 30 | * JPA annotations @OneToOne, @OneToMany, @ManyToOne, @ManyToMany and fetch = FetchType.LAZY 31 | 32 | ## Credits 33 | 34 | * [J2EE Design Patterns](http://www.amazon.com/J2EE-Design-Patterns-William-Crawford/dp/0596004273/ref=sr_1_2) 35 | -------------------------------------------------------------------------------- /module/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: pattern 3 | title: Module 4 | folder: module 5 | permalink: /patterns/module/ 6 | pumlid: JShB3OGm303HLg20nFVjnYGM1CN6ycTfVtFSsnjfzY5jPgUqkLqHwXy0mxUU8wuyqidQ8q4IjJqCO-QBWGOtVh5qyd5AKOmW4mT6Nu2-ZiAekapH_hkcSTNa-GC0 7 | categories: Creational Pattern 8 | tags: 9 | - Java 10 | - Difficulty-Beginner 11 | --- 12 | 13 | ## Intent 14 | Module pattern is used to implement the concept of software modules, defined by modular programming, in a programming language with incomplete direct support for the concept. 15 | 16 | ![alt text](./etc/module.png "Module") 17 | 18 | ## Applicability 19 | The Module pattern can be considered a creational pattern and a structural pattern. It manages the creation and organization of other elements, and groups them as the structural pattern does. 20 | 21 | An object that applies this pattern can provide the equivalent of a namespace, providing the initialization and finalization process of a static class or a class with static members with cleaner, more concise syntax and semantics. 22 | 23 | ## Credits 24 | 25 | * [Module](https://en.wikipedia.org/wiki/Module_pattern) 26 | -------------------------------------------------------------------------------- /converter/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: pattern 3 | title: Converter 4 | folder: converter 5 | permalink: /patterns/converter/ 6 | categories: 7 | tags: 8 | - Java 9 | - Difficulty-Beginner 10 | --- 11 | 12 | ## Intent 13 | The purpose of the Converter Pattern is to provide a generic, common way of bidirectional 14 | conversion between corresponding types, allowing a clean implementation in which the types do not 15 | need to be aware of each other. Moreover, the Converter Pattern introduces bidirectional collection 16 | mapping, reducing a boilerplate code to minimum. 17 | 18 | ![alt text](./etc/converter.png "Converter Pattern") 19 | 20 | ## Applicability 21 | Use the Converter Pattern in the following situations: 22 | 23 | * When you have types that logically correspond which other and you need to convert entities between them 24 | * When you want to provide different ways of types conversions depending on a context 25 | * Whenever you introduce a DTO (Data transfer object), you will probably need to convert it into the domain equivalence 26 | 27 | ## Credits 28 | 29 | * [Converter](http://www.xsolve.pl/blog/converter-pattern-in-java-8/) 30 | -------------------------------------------------------------------------------- /semaphore/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: pattern 3 | title: Semaphore 4 | folder: semaphore 5 | permalink: /patterns/semaphore/ 6 | pumlid: HSV14SCm20J0Lk82BFxf1ikCfOn06ZZizfDVVhjRjphobFJnQi2ADv7pKwwEbaU6U9q6CPGwbVh8Xy5E7xvvFoNwPVjYGDo2bEC72b5URRgGeFvNqhMirF45 7 | categories: Concurrency 8 | tags: 9 | - Java 10 | - Difficulty-Intermediate 11 | --- 12 | 13 | ## Also known as 14 | Counting Semaphore 15 | 16 | ## Intent 17 | Create a lock which mediates access to a pool of resources. 18 | Only a limited number of threads, specified at the creation 19 | of the semaphore, can access the resources at any given time. 20 | A semaphore which only allows one concurrent access to a resource 21 | is called a binary semaphore. 22 | 23 | ![alt text](./etc/semaphore.png "Semaphore") 24 | 25 | ## Applicability 26 | Use a Semaphore when 27 | 28 | * you have a pool of resources to allocate to different threads 29 | * concurrent access to a resource could lead to a race condition 30 | 31 | ## Credits 32 | 33 | * [Semaphore(programming)] (http://en.wikipedia.org/wiki/Semaphore_(programming)) 34 | * [Semaphores] (http://tutorials.jenkov.com/java-concurrency/semaphores.html) 35 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014-2016 Ilkka Seppälä 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /specification/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: pattern 3 | title: Specification 4 | folder: specification 5 | permalink: /patterns/specification/ 6 | pumlid: LSX14i8m20NGg-W16lRU1YcsE0d9mCTUNxVkthoxkVJQjQBVJc3bWoZuQeVXh6UbXao7EfhCGTRhOd3Gcp-yxPfs-BOOqF2amVa3vLAnbmd3ffD2_gTLZBPgz2y0 7 | categories: Behavioral 8 | tags: 9 | - Java 10 | - Difficulty-Beginner 11 | --- 12 | 13 | ## Also known as 14 | Filter, Criteria 15 | 16 | ## Intent 17 | Specification pattern separates the statement of how to match a 18 | candidate, from the candidate object that it is matched against. As well as its 19 | usefulness in selection, it is also valuable for validation and for building to 20 | order 21 | 22 | ![alt text](./etc/specification.png "Specification") 23 | 24 | ## Applicability 25 | Use the Specification pattern when 26 | 27 | * you need to select a subset of objects based on some criteria, and to refresh the selection at various times 28 | * you need to check that only suitable objects are used for a certain role (validation) 29 | 30 | ## Related patterns 31 | 32 | * Repository 33 | 34 | ## Credits 35 | 36 | * [Martin Fowler - Specifications](http://martinfowler.com/apsupp/spec.pdf) 37 | -------------------------------------------------------------------------------- /composite/etc/composite.urm.puml: -------------------------------------------------------------------------------- 1 | @startuml 2 | package com.iluwatar.composite { 3 | class App { 4 | - LOGGER : Logger {static} 5 | + App() 6 | + main(args : String[]) {static} 7 | } 8 | class Letter { 9 | - c : char 10 | + Letter(c : char) 11 | # printThisAfter() 12 | # printThisBefore() 13 | } 14 | abstract class LetterComposite { 15 | - children : List 16 | + LetterComposite() 17 | + add(letter : LetterComposite) 18 | + count() : int 19 | + print() 20 | # printThisAfter() {abstract} 21 | # printThisBefore() {abstract} 22 | } 23 | class Messenger { 24 | + Messenger() 25 | ~ messageFromElves() : LetterComposite 26 | ~ messageFromOrcs() : LetterComposite 27 | } 28 | class Sentence { 29 | + Sentence(words : List) 30 | # printThisAfter() 31 | # printThisBefore() 32 | } 33 | class Word { 34 | + Word(letters : List) 35 | # printThisAfter() 36 | # printThisBefore() 37 | } 38 | } 39 | LetterComposite --> "-children" LetterComposite 40 | Letter --|> LetterComposite 41 | Sentence --|> LetterComposite 42 | Word --|> LetterComposite 43 | @enduml -------------------------------------------------------------------------------- /dependency-injection/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: pattern 3 | title: Dependency Injection 4 | folder: dependency-injection 5 | permalink: /patterns/dependency-injection/ 6 | pumlid: RSdB3SCW303GLPe1mFTkunWhSGG6-PEesxS3zFQajubIpyPf_NL6B7y363xra3XpJsUZgS4QbUO0wVbWeC65DvR6BeUMXH5iwZ3GVu36YxMnqgU8NamXKu63_aPD6tNbw5y0 7 | categories: Behavioral 8 | tags: 9 | - Java 10 | - Difficulty-Beginner 11 | --- 12 | 13 | ## Intent 14 | Dependency Injection is a software design pattern in which one or 15 | more dependencies (or services) are injected, or passed by reference, into a 16 | dependent object (or client) and are made part of the client's state. The 17 | pattern separates the creation of a client's dependencies from its own 18 | behavior, which allows program designs to be loosely coupled and to follow the 19 | inversion of control and single responsibility principles. 20 | 21 | ![alt text](./etc/dependency-injection.png "Dependency Injection") 22 | 23 | ## Applicability 24 | Use the Dependency Injection pattern when 25 | 26 | * when you need to remove knowledge of concrete implementation from object 27 | * to enable unit testing of classes in isolation using mock objects or stubs 28 | -------------------------------------------------------------------------------- /monostate/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: pattern 3 | title: MonoState 4 | folder: monostate 5 | permalink: /patterns/monostate/ 6 | pumlid: HSV14OGm20NGLjO23FVj1YEZsGaa0nzjVxrvUszfLdlkaju_9p3ZI-HybwFXp2r3l0w364eTIgtdpM2d7r-yxXBji7Ko86v1ol60TDW8C8G4zLr9rp9J-ny0 7 | categories: Creational 8 | tags: 9 | - Java 10 | - Difficulty-Beginner 11 | --- 12 | 13 | ## Also known as 14 | Borg 15 | 16 | ## Intent 17 | Enforces a behaviour like sharing the same state amongst all instances. 18 | 19 | ![alt text](./etc/monostate.png "MonoState") 20 | 21 | ## Applicability 22 | Use the Monostate pattern when 23 | 24 | * The same state must be shared across all instances of a class. 25 | * Typically this pattern might be used everywhere a Singleton might be used. Singleton usage however is not transparent, Monostate usage is. 26 | * Monostate has one major advantage over singleton. The subclasses might decorate the shared state as they wish and hence can provide dynamically different behaviour than the base class. 27 | 28 | ## Typical Use Case 29 | 30 | * the logging class 31 | * managing a connection to a database 32 | * file manager 33 | 34 | ## Real world examples 35 | 36 | Yet to see this. 37 | -------------------------------------------------------------------------------- /template-method/etc/template-method.urm.puml: -------------------------------------------------------------------------------- 1 | @startuml 2 | package com.iluwatar.templatemethod { 3 | class App { 4 | + App() 5 | + main(args : String[]) {static} 6 | } 7 | class HalflingThief { 8 | - method : StealingMethod 9 | + HalflingThief(method : StealingMethod) 10 | + changeMethod(method : StealingMethod) 11 | + steal() 12 | } 13 | class HitAndRunMethod { 14 | - LOGGER : Logger {static} 15 | + HitAndRunMethod() 16 | # confuseTarget(target : String) 17 | # pickTarget() : String 18 | # stealTheItem(target : String) 19 | } 20 | abstract class StealingMethod { 21 | - LOGGER : Logger {static} 22 | + StealingMethod() 23 | # confuseTarget(String) {abstract} 24 | # pickTarget() : String {abstract} 25 | + steal() 26 | # stealTheItem(String) {abstract} 27 | } 28 | class SubtleMethod { 29 | - LOGGER : Logger {static} 30 | + SubtleMethod() 31 | # confuseTarget(target : String) 32 | # pickTarget() : String 33 | # stealTheItem(target : String) 34 | } 35 | } 36 | HalflingThief --> "-method" StealingMethod 37 | HitAndRunMethod --|> StealingMethod 38 | SubtleMethod --|> StealingMethod 39 | @enduml -------------------------------------------------------------------------------- /business-delegate/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: pattern 3 | title: Business Delegate 4 | folder: business-delegate 5 | permalink: /patterns/business-delegate/ 6 | pumlid: POl13SCm3CHMQGU8zUysgYCuBcJ5a4x9-l6_Fu84tzsgvYxf-Zg06HyYvxkqZYE_6UBrD8YXr7DGrxmPxFJZYxTTeZVR9WFY5ZGu5j2wkad4wYgD8IIe_xQaZp9pw0C0 7 | categories: Business Tier 8 | tags: 9 | - Java 10 | - Difficulty-Intermediate 11 | --- 12 | 13 | ## Intent 14 | The Business Delegate pattern adds an abstraction layer between 15 | presentation and business tiers. By using the pattern we gain loose coupling 16 | between the tiers and encapsulate knowledge about how to locate, connect to, 17 | and interact with the business objects that make up the application. 18 | 19 | ![alt text](./etc/business-delegate.png "Business Delegate") 20 | 21 | ## Applicability 22 | Use the Business Delegate pattern when 23 | 24 | * you want loose coupling between presentation and business tiers 25 | * you want to orchestrate calls to multiple business services 26 | * you want to encapsulate service lookups and service calls 27 | 28 | ## Credits 29 | 30 | * [J2EE Design Patterns](http://www.amazon.com/J2EE-Design-Patterns-William-Crawford/dp/0596004273/ref=sr_1_2) 31 | -------------------------------------------------------------------------------- /memento/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: pattern 3 | title: Memento 4 | folder: memento 5 | permalink: /patterns/memento/ 6 | pumlid: DSgn4OCm30NGLM00h3xR2AC3SvRiaxx2-g59zugtDgiz3qdlomNC-10vF-Lik7BF4A_388PIXrBh-J3OwUOlRuT4EssR38XRa7Ay81Lz_o11_RkaQvcf_GS0 7 | categories: Behavioral 8 | tags: 9 | - Java 10 | - Gang Of Four 11 | - Difficulty-Intermediate 12 | --- 13 | 14 | ## Also known as 15 | Token 16 | 17 | ## Intent 18 | Without violating encapsulation, capture and externalize an 19 | object's internal state so that the object can be restored to this state later. 20 | 21 | ![alt text](./etc/memento.png "Memento") 22 | 23 | ## Applicability 24 | Use the Memento pattern when 25 | 26 | * a snapshot of an object's state must be saved so that it can be restored to that state later, and 27 | * a direct interface to obtaining the state would expose implementation details and break the object's encapsulation 28 | 29 | ## Real world examples 30 | 31 | * [java.util.Date](http://docs.oracle.com/javase/8/docs/api/java/util/Date.html) 32 | 33 | ## Credits 34 | 35 | * [Design Patterns: Elements of Reusable Object-Oriented Software](http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612) 36 | -------------------------------------------------------------------------------- /service-locator/etc/service-locator.urm.puml: -------------------------------------------------------------------------------- 1 | @startuml 2 | package com.iluwatar.servicelocator { 3 | class App { 4 | + App() 5 | + main(args : String[]) {static} 6 | } 7 | class InitContext { 8 | - LOGGER : Logger {static} 9 | + InitContext() 10 | + lookup(serviceName : String) : Object 11 | } 12 | interface Service { 13 | + execute() {abstract} 14 | + getId() : int {abstract} 15 | + getName() : String {abstract} 16 | } 17 | class ServiceCache { 18 | - LOGGER : Logger {static} 19 | - serviceCache : Map 20 | + ServiceCache() 21 | + addService(newService : Service) 22 | + getService(serviceName : String) : Service 23 | } 24 | class ServiceImpl { 25 | - LOGGER : Logger {static} 26 | - id : int 27 | - serviceName : String 28 | + ServiceImpl(serviceName : String) 29 | + execute() 30 | + getId() : int 31 | + getName() : String 32 | } 33 | class ServiceLocator { 34 | - serviceCache : ServiceCache {static} 35 | - ServiceLocator() 36 | + getService(serviceJndiName : String) : Service {static} 37 | } 38 | } 39 | ServiceLocator --> "-serviceCache" ServiceCache 40 | ServiceImpl ..|> Service 41 | @enduml -------------------------------------------------------------------------------- /step-builder/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: pattern 3 | title: Step Builder 4 | folder: step-builder 5 | permalink: /patterns/step-builder/ 6 | pumlid: LOZ93SCm3C1MQGQmzUysYYqaAcJ5q96i7t_x8KXkh4soKvfypeZfNm33fnuSP-xfPEtI88tQhW4i-M2WmGzlB9sS3oqJ8yZKOQ0lWOLPzcJfAoZQtwXfeyuSyW80 7 | categories: Creational 8 | tags: 9 | - Java 10 | - Difficulty-Intermediate 11 | --- 12 | 13 | ## Intent 14 | An extension of the Builder pattern that fully guides the user through the creation of the object with no chances of confusion. 15 | The user experience will be much more improved by the fact that he will only see the next step methods available, NO build method until is the right time to build the object. 16 | 17 | ![alt text](./etc/step-builder.png "Step Builder") 18 | 19 | ## Applicability 20 | Use the Step Builder pattern when the algorithm for creating a complex object should be independent of the parts that make up the object and how they're assembled the construction process must allow different representations for the object that's constructed when in the process of constructing the order is important. 21 | 22 | ## Credits 23 | 24 | * [Marco Castigliego - Step Builder](http://rdafbn.blogspot.co.uk/2012/07/step-builder-pattern_28.html) 25 | -------------------------------------------------------------------------------- /object-mother/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: pattern 3 | title: Object Mother 4 | folder: object-mother 5 | permalink: /patterns/object-mother/ 6 | pumlid: LOr13iCW30JlVKNx0E3UKxxYW9KGWK7sklb-wR6dtLbfj9k15DxRurKbDo_isfudCEsTaj8TZuhJTpVMF0GiY7dqL9lVjDHqqOT2OQk7X4a0grZgPAkaiL-S4Vh0kOYH_vVeskFyVMyiPUKN 7 | categories: Creational 8 | tags: 9 | - Java 10 | - Difficulty-Beginner 11 | --- 12 | 13 | ## Object Mother 14 | Define a factory of immutable content with separated builder and factory interfaces. 15 | 16 | ![alt text](./etc/object-mother.png "Object Mother") 17 | 18 | ## Applicability 19 | Use the Object Mother pattern when 20 | 21 | * You want consistent objects over several tests 22 | * you want to reduce code for creation of objects in tests 23 | * every test should run with fresh data 24 | 25 | ## Credits 26 | 27 | * [Answer by David Brown](http://stackoverflow.com/questions/923319/what-is-an-objectmother) to the stackoverflow question: [What is an ObjectMother?](http://stackoverflow.com/questions/923319/what-is-an-objectmother) 28 | 29 | * [c2wiki - Object Mother](http://c2.com/cgi/wiki?ObjectMother) 30 | 31 | * [Nat Pryce - Test Data Builders: an alternative to the Object Mother pattern](http://www.natpryce.com/articles/000714.html) 32 | -------------------------------------------------------------------------------- /module/error.txt: -------------------------------------------------------------------------------- 1 | ==== 2 | The MIT License 3 | Copyright (c) 2014 Ilkka Seppälä 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | ==== 23 | 24 | -------------------------------------------------------------------------------- /module/output.txt: -------------------------------------------------------------------------------- 1 | ==== 2 | The MIT License 3 | Copyright (c) 2014 Ilkka Seppälä 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | ==== 23 | 24 | -------------------------------------------------------------------------------- /caching/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: pattern 3 | title: Caching 4 | folder: caching 5 | permalink: /patterns/caching/ 6 | pumlid: DSRB4OKm2030LhG0m_rrWyWaE0bc-6ZxpujxsbMKUXwSrfSMCVq7OFYKAj5oJsUZIuCr2bq3fEU3WGOdthWTx59rcnZ1fWu3_GqGKXEjm47VIzeeCqV_0m00 7 | categories: Other 8 | tags: 9 | - Java 10 | - Difficulty-Intermediate 11 | - Performance 12 | --- 13 | 14 | ## Intent 15 | To avoid expensive re-acquisition of resources by not releasing 16 | the resources immediately after their use. The resources retain their identity, are kept in some 17 | fast-access storage, and are re-used to avoid having to acquire them again. 18 | 19 | ![alt text](./etc/caching.png "Caching") 20 | 21 | ## Applicability 22 | Use the Caching pattern(s) when 23 | 24 | * Repetitious acquisition, initialization, and release of the same resource causes unnecessary performance overhead. 25 | 26 | ## Credits 27 | 28 | * [Write-through, write-around, write-back: Cache explained](http://www.computerweekly.com/feature/Write-through-write-around-write-back-Cache-explained) 29 | * [Read-Through, Write-Through, Write-Behind, and Refresh-Ahead Caching](https://docs.oracle.com/cd/E15357_01/coh.360/e15723/cache_rtwtwbra.htm#COHDG5177) 30 | * [Cache-Aside](https://msdn.microsoft.com/en-us/library/dn589799.aspx) 31 | -------------------------------------------------------------------------------- /double-checked-locking/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: pattern 3 | title: Double Checked Locking 4 | folder: double-checked-locking 5 | permalink: /patterns/double-checked-locking/ 6 | pumlid: TSdH4SCW203GLTe1bFzkGv1J6qGFeLc_MI1_x-wzkv94uJ1vDVUrFm26LwxTMnonsMYgitgcEQ1BNEXeyCKVfiAxLqqBtTbqmy1z0ygCGpXHOpgv99bqTgt0JW-LmqPUCUGF 7 | categories: Concurrency 8 | tags: 9 | - Java 10 | - Difficulty-Beginner 11 | - Idiom 12 | --- 13 | 14 | ## Intent 15 | Reduce the overhead of acquiring a lock by first testing the 16 | locking criterion (the "lock hint") without actually acquiring the lock. Only 17 | if the locking criterion check indicates that locking is required does the 18 | actual locking logic proceed. 19 | 20 | ![alt text](./etc/double_checked_locking_1.png "Double Checked Locking") 21 | 22 | ## Applicability 23 | Use the Double Checked Locking pattern when 24 | 25 | * there is a concurrent access in object creation, e.g. singleton, where you want to create single instance of the same class and checking if it's null or not maybe not be enough when there are two or more threads that checks if instance is null or not. 26 | * there is a concurrent access on a method where method's behaviour changes according to the some constraints and these constraint change within this method. 27 | -------------------------------------------------------------------------------- /event-asynchronous/src/main/resources/config.properties: -------------------------------------------------------------------------------- 1 | # 2 | # The MIT License 3 | # Copyright (c) 2014-2016 Ilkka Seppälä 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in 13 | # all copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | # THE SOFTWARE. 22 | # 23 | 24 | INTERACTIVE_MODE=NO -------------------------------------------------------------------------------- /aggregator-microservices/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: pattern 3 | title: Aggregator Microservices 4 | folder: aggregator-microservices 5 | permalink: /patterns/aggregator-microservices/ 6 | pumlid: JOov3SCm301NIGQGs7iRXYPa1g8ayB7NjuiKwGvtmBrbKC-Tq_hhY5Y-0HXUjKaS-Kbdepc2HrIQ2jBpma23BvvOTdPfeooCO1iEYlu0O6l63MDQKI6Rp-CKOWSE-ey_NzEqhjH-0m00 7 | categories: Architectural 8 | tags: 9 | - Java 10 | - Spring 11 | --- 12 | 13 | ## Intent 14 | 15 | The user makes a single call to the Aggregator, and the aggregator then calls each relevant microservice and collects 16 | the data, apply business logic to it, and further publish is as a REST Endpoint. 17 | More variations of the aggregator are: 18 | - Proxy Microservice Design Pattern: A different microservice is called upon the business need. 19 | - Chained Microservice Design Pattern: In this case each microservice is dependent/ chained to a series 20 | of other microservices. 21 | 22 | ![alt text](./etc/aggregator-microservice.png "Aggregator Microservice") 23 | 24 | ## Applicability 25 | 26 | Use the Aggregator Microservices pattern when you need a unified API for various microservices, regardless the client device. 27 | 28 | ## Credits 29 | 30 | * [Microservice Design Patterns](http://blog.arungupta.me/microservice-design-patterns/) 31 | -------------------------------------------------------------------------------- /object-mother/etc/object-mother.urm.puml: -------------------------------------------------------------------------------- 1 | @startuml 2 | package com.iluwatar.objectmother { 3 | class King { 4 | ~ isDrunk : boolean 5 | ~ isHappy : boolean 6 | + King() 7 | + flirt(queen : Queen) 8 | + isHappy() : boolean 9 | + makeDrunk() 10 | + makeHappy() 11 | + makeSober() 12 | + makeUnhappy() 13 | } 14 | class Queen { 15 | - isDrunk : boolean 16 | - isFlirty : boolean 17 | - isHappy : boolean 18 | + Queen() 19 | + getFlirted(king : King) : boolean 20 | + isFlirty() : boolean 21 | + makeDrunk() 22 | + makeHappy() 23 | + makeSober() 24 | + makeUnhappy() 25 | + setFlirtiness(flirtiness : boolean) 26 | } 27 | interface Royalty { 28 | + makeDrunk() {abstract} 29 | + makeHappy() {abstract} 30 | + makeSober() {abstract} 31 | + makeUnhappy() {abstract} 32 | } 33 | class RoyaltyObjectMother { 34 | + RoyaltyObjectMother() 35 | + createDrunkKing() : King {static} 36 | + createFlirtyQueen() : Queen {static} 37 | + createHappyDrunkKing() : King {static} 38 | + createHappyKing() : King {static} 39 | + createNotFlirtyQueen() : Queen {static} 40 | + createSoberUnhappyKing() : King {static} 41 | } 42 | } 43 | King ..|> Royalty 44 | Queen ..|> Royalty 45 | @enduml -------------------------------------------------------------------------------- /api-gateway/api-gateway-service/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | # 2 | # The MIT License 3 | # Copyright (c) 2014-2016 Ilkka Seppälä 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in 13 | # all copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | # THE SOFTWARE. 22 | # 23 | 24 | server.port=50004 -------------------------------------------------------------------------------- /api-gateway/image-microservice/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | # 2 | # The MIT License 3 | # Copyright (c) 2014-2016 Ilkka Seppälä 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in 13 | # all copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | # THE SOFTWARE. 22 | # 23 | 24 | server.port=50005 -------------------------------------------------------------------------------- /api-gateway/price-microservice/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | # 2 | # The MIT License 3 | # Copyright (c) 2014-2016 Ilkka Seppälä 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in 13 | # all copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | # THE SOFTWARE. 22 | # 23 | 24 | server.port=50006 -------------------------------------------------------------------------------- /naked-objects/integtests/src/test/java/domainapp/integtests/specs/modules/simple/SimpleObjectSpec_listAllAndCreate.feature: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with 4 | # this work for additional information regarding copyright ownership. 5 | # The ASF licenses this file to You under the Apache License, Version 2.0 6 | # (the "License"); you may not use this file except in compliance with 7 | # the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | @SimpleObjectsFixture 18 | Feature: List and Create New Simple Objects 19 | 20 | @integration 21 | Scenario: Existing simple objects can be listed and new ones created 22 | Given there are initially 3 simple objects 23 | When I create a new simple object 24 | Then there are 4 simple objects 25 | 26 | -------------------------------------------------------------------------------- /queue-load-leveling/etc/queue-load-leveling.urm.puml: -------------------------------------------------------------------------------- 1 | @startuml 2 | package com.iluwatar.queue.load.leveling { 3 | class App { 4 | - LOGGER : Logger {static} 5 | - SHUTDOWN_TIME : int {static} 6 | + App() 7 | + main(args : String[]) {static} 8 | } 9 | class Message { 10 | - msg : String 11 | + Message(msg : String) 12 | + getMsg() : String 13 | + toString() : String 14 | } 15 | class MessageQueue { 16 | - LOGGER : Logger {static} 17 | - blkQueue : BlockingQueue 18 | + MessageQueue() 19 | + retrieveMsg() : Message 20 | + submitMsg(msg : Message) 21 | } 22 | class ServiceExecutor { 23 | - LOGGER : Logger {static} 24 | - msgQueue : MessageQueue 25 | + ServiceExecutor(msgQueue : MessageQueue) 26 | + run() 27 | } 28 | interface Task { 29 | + submit(Message) {abstract} 30 | } 31 | class TaskGenerator { 32 | - LOGGER : Logger {static} 33 | - msgCount : int 34 | - msgQueue : MessageQueue 35 | + TaskGenerator(msgQueue : MessageQueue, msgCount : int) 36 | + run() 37 | + submit(msg : Message) 38 | } 39 | } 40 | MessageQueue --> "-blkQueue" Message 41 | ServiceExecutor --> "-msgQueue" MessageQueue 42 | TaskGenerator --> "-msgQueue" MessageQueue 43 | TaskGenerator ..|> Task 44 | @enduml -------------------------------------------------------------------------------- /aggregator-microservices/aggregator-service/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | # 2 | # The MIT License 3 | # Copyright (c) 2014-2016 Ilkka Seppälä 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in 13 | # all copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | # THE SOFTWARE. 22 | # 23 | 24 | server.port=50004 -------------------------------------------------------------------------------- /aggregator-microservices/inventory-microservice/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | # 2 | # The MIT License 3 | # Copyright (c) 2014-2016 Ilkka Seppälä 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in 13 | # all copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | # THE SOFTWARE. 22 | # 23 | 24 | server.port=51516 -------------------------------------------------------------------------------- /iterator/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: pattern 3 | title: Iterator 4 | folder: iterator 5 | permalink: /patterns/iterator/ 6 | pumlid: FSV13OGm30NHLg00uljsOu85HeaJsTzB-yjfBwCtgrfjUKXwMovWneV8-IcduiezGxmEWnXA7PsqvSDWfvk_l1qIUjes6H2teCxnWlGDOpW9wdzAUYypU_i1 7 | categories: Behavioral 8 | tags: 9 | - Java 10 | - Difficulty-Beginner 11 | - Gang Of Four 12 | --- 13 | 14 | ## Also known as 15 | Cursor 16 | 17 | ## Intent 18 | Provide a way to access the elements of an aggregate object 19 | sequentially without exposing its underlying representation. 20 | 21 | ![alt text](./etc/iterator_1.png "Iterator") 22 | 23 | ## Applicability 24 | Use the Iterator pattern 25 | 26 | * to access an aggregate object's contents without exposing its internal representation 27 | * to support multiple traversals of aggregate objects 28 | * to provide a uniform interface for traversing different aggregate structures 29 | 30 | ## Real world examples 31 | 32 | * [java.util.Iterator](http://docs.oracle.com/javase/8/docs/api/java/util/Iterator.html) 33 | * [java.util.Enumeration](http://docs.oracle.com/javase/8/docs/api/java/util/Enumeration.html) 34 | 35 | ## Credits 36 | 37 | * [Design Patterns: Elements of Reusable Object-Oriented Software](http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612) 38 | -------------------------------------------------------------------------------- /model-view-presenter/etc/data/test.txt: -------------------------------------------------------------------------------- 1 | ==== 2 | The MIT License 3 | Copyright (c) 2014-2016 Ilkka Seppälä 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | ==== 23 | 24 | Test line 1 25 | Test line 2 -------------------------------------------------------------------------------- /aggregator-microservices/information-microservice/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | # 2 | # The MIT License 3 | # Copyright (c) 2014-2016 Ilkka Seppälä 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in 13 | # all copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | # THE SOFTWARE. 22 | # 23 | 24 | server.port=51515 -------------------------------------------------------------------------------- /feature-toggle/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: pattern 3 | title: Feature Toggle 4 | folder: feature-toggle 5 | permalink: /patterns/feature-toggle/ 6 | pumlid: NSZ14G8X30NGLhG0oDrk8XjPd12OvCTjNy_UthpxiAPvIBhUJc37WyZvgdtWp6U6U5i6CTIs9WtDYy5ER_vmEIH6jx8P4BUWoV43lOIHBWMhTnKIjB-gwRFkdFe5 7 | categories: Behavioral 8 | tags: 9 | - Java 10 | - Difficulty-Beginner 11 | --- 12 | 13 | ## Also known as 14 | Feature Flag 15 | 16 | ## Intent 17 | Used to switch code execution paths based on properties or groupings. Allowing new features to be released, tested 18 | and rolled out. Allowing switching back to the older feature quickly if needed. It should be noted that this pattern, 19 | can easily introduce code complexity. There is also cause for concern that the old feature that the toggle is eventually 20 | going to phase out is never removed, causing redundant code smells and increased maintainability. 21 | 22 | ![alt text](./etc/feature-toggle.png "Feature Toggle") 23 | 24 | ## Applicability 25 | Use the Feature Toogle pattern when 26 | 27 | * Giving different features to different users. 28 | * Rolling out a new feature incrementally. 29 | * Switching between development and production environments. 30 | 31 | ## Credits 32 | 33 | * [Martin Fowler 29 October 2010 (2010-10-29).](http://martinfowler.com/bliki/FeatureToggle.html) -------------------------------------------------------------------------------- /naked-objects/etc/naked-objects-dom.urm.puml: -------------------------------------------------------------------------------- 1 | @startuml 2 | package domainapp.dom.app.homepage { 3 | class HomePageService { 4 | ~ container : DomainObjectContainer 5 | + HomePageService() 6 | + homePage() : HomePageViewModel 7 | } 8 | class HomePageViewModel { 9 | ~ simpleObjects : SimpleObjects 10 | + HomePageViewModel() 11 | + getObjects() : List 12 | + title() : String 13 | } 14 | } 15 | package domainapp.dom.modules.simple { 16 | class SimpleObject { 17 | - container : DomainObjectContainer 18 | - name : String 19 | + SimpleObject() 20 | + compareTo(other : SimpleObject) : int 21 | + default0UpdateName() : String 22 | + getName() : String 23 | + getVersionSequence() : Long 24 | + setName(name : String) 25 | + title() : TranslatableString 26 | + updateName(name : String) : SimpleObject 27 | + validateUpdateName(name : String) : TranslatableString 28 | } 29 | class SimpleObjects { 30 | ~ container : DomainObjectContainer 31 | + SimpleObjects() 32 | + create(name : String) : SimpleObject 33 | + findByName(name : String) : List 34 | + listAll() : List 35 | + title() : TranslatableString 36 | } 37 | } 38 | HomePageViewModel --> "-simpleObjects" SimpleObjects 39 | @enduml -------------------------------------------------------------------------------- /dependency-injection/etc/dependency-injection.urm.puml: -------------------------------------------------------------------------------- 1 | @startuml 2 | package com.iluwatar.dependency.injection { 3 | class AdvancedWizard { 4 | - tobacco : Tobacco 5 | + AdvancedWizard(tobacco : Tobacco) 6 | + smoke() 7 | } 8 | class App { 9 | + App() 10 | + main(args : String[]) {static} 11 | } 12 | class GuiceWizard { 13 | - tobacco : Tobacco 14 | + GuiceWizard(tobacco : Tobacco) 15 | + smoke() 16 | } 17 | class OldTobyTobacco { 18 | + OldTobyTobacco() 19 | } 20 | class RivendellTobacco { 21 | + RivendellTobacco() 22 | } 23 | class SecondBreakfastTobacco { 24 | + SecondBreakfastTobacco() 25 | } 26 | class SimpleWizard { 27 | - tobacco : OldTobyTobacco 28 | + SimpleWizard() 29 | + smoke() 30 | } 31 | abstract class Tobacco { 32 | - LOGGER : Logger {static} 33 | + Tobacco() 34 | + smoke(wizard : Wizard) 35 | } 36 | interface Wizard { 37 | + smoke() {abstract} 38 | } 39 | } 40 | SimpleWizard --> "-tobacco" OldTobyTobacco 41 | AdvancedWizard --> "-tobacco" Tobacco 42 | GuiceWizard --> "-tobacco" Tobacco 43 | AdvancedWizard ..|> Wizard 44 | GuiceWizard ..|> Wizard 45 | OldTobyTobacco --|> Tobacco 46 | RivendellTobacco --|> Tobacco 47 | SecondBreakfastTobacco --|> Tobacco 48 | SimpleWizard ..|> Wizard 49 | @enduml -------------------------------------------------------------------------------- /model-view-controller/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: pattern 3 | title: Model-View-Controller 4 | folder: model-view-controller 5 | permalink: /patterns/model-view-controller/ 6 | pumlid: ROl13SCm201NQGUm-NSRQgE42h258Lw_wR-_qvtkoTOaEwNBuuoOwmNWkEl1SUOx5taR5cHHsr1WoOs13X-yi7HQV5YP645k2nJN3Q2ZavIBQPVVwqFajXJjVwdfMcUgV040 7 | categories: Presentation Tier 8 | tags: 9 | - Java 10 | - Difficulty-Intermediate 11 | --- 12 | 13 | ## Intent 14 | Separate the user interface into three interconnected components: 15 | the model, the view and the controller. Let the model manage the data, the view 16 | display the data and the controller mediate updating the data and redrawing the 17 | display. 18 | 19 | ![alt text](./etc/model-view-controller.png "Model-View-Controller") 20 | 21 | ## Applicability 22 | Use the Model-View-Controller pattern when 23 | 24 | * you want to clearly separate the domain data from its user interface representation 25 | 26 | ## Credits 27 | 28 | * [Trygve Reenskaug - Model-view-controller](http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller) 29 | * [J2EE Design Patterns](http://www.amazon.com/J2EE-Design-Patterns-William-Crawford/dp/0596004273/ref=sr_1_2) 30 | * [Patterns of Enterprise Application Architecture](http://www.amazon.com/Patterns-Enterprise-Application-Architecture-Martin/dp/0321127420) 31 | -------------------------------------------------------------------------------- /front-controller/etc/front-controller.urm.puml: -------------------------------------------------------------------------------- 1 | @startuml 2 | package com.iluwatar.front.controller { 3 | class App { 4 | + App() 5 | + main(args : String[]) {static} 6 | } 7 | class ArcherCommand { 8 | + ArcherCommand() 9 | + process() 10 | } 11 | class ArcherView { 12 | - LOGGER : Logger {static} 13 | + ArcherView() 14 | + display() 15 | } 16 | class CatapultCommand { 17 | + CatapultCommand() 18 | + process() 19 | } 20 | class CatapultView { 21 | - LOGGER : Logger {static} 22 | + CatapultView() 23 | + display() 24 | } 25 | interface Command { 26 | + process() {abstract} 27 | } 28 | class ErrorView { 29 | - LOGGER : Logger {static} 30 | + ErrorView() 31 | + display() 32 | } 33 | class FrontController { 34 | + FrontController() 35 | - getCommand(request : String) : Command 36 | - getCommandClass(request : String) : Class {static} 37 | + handleRequest(request : String) 38 | } 39 | class UnknownCommand { 40 | + UnknownCommand() 41 | + process() 42 | } 43 | interface View { 44 | + display() {abstract} 45 | } 46 | } 47 | ArcherCommand ..|> Command 48 | ArcherView ..|> View 49 | CatapultCommand ..|> Command 50 | CatapultView ..|> View 51 | ErrorView ..|> View 52 | UnknownCommand ..|> Command 53 | @enduml -------------------------------------------------------------------------------- /naked-objects/dom/src/main/java/META-INF/persistence.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /naked-objects/webapp/src/main/webapp/scripts/application.js: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * Copyright (c) 2014-2016 Ilkka Seppälä 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in 13 | * all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | * THE SOFTWARE. 22 | */ 23 | $(document).ready(function() { 24 | /// here... 25 | }); -------------------------------------------------------------------------------- /null-object/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: pattern 3 | title: Null Object 4 | folder: null-object 5 | permalink: /patterns/null-object/ 6 | pumlid: JSV14SCm20J0Lk829Fxf1cF6bWSX3JhYzfDdVhjRSx4yDCDU5p3NcoZugMV3bNik3HaETLGPdPhbm-2WcpzS3btjz38PqF15dTSFv6bMndwhW1Jo_vhHwynkNm00 7 | categories: Behavioral 8 | tags: 9 | - Java 10 | - Difficulty-Beginner 11 | --- 12 | 13 | ## Intent 14 | In most object-oriented languages, such as Java or C#, references 15 | may be null. These references need to be checked to ensure they are not null 16 | before invoking any methods, because methods typically cannot be invoked on 17 | null references. Instead of using a null reference to convey absence of an 18 | object (for instance, a non-existent customer), one uses an object which 19 | implements the expected interface, but whose method body is empty. The 20 | advantage of this approach over a working default implementation is that a Null 21 | Object is very predictable and has no side effects: it does nothing. 22 | 23 | ![alt text](./etc/null-object.png "Null Object") 24 | 25 | ## Applicability 26 | Use the Null Object pattern when 27 | 28 | * you want to avoid explicit null checks and keep the algorithm elegant and easy to read. 29 | 30 | ## Credits 31 | * [Pattern Languages of Program Design](http://www.amazon.com/Pattern-Languages-Program-Design-Coplien/dp/0201607344/ref=sr_1_1) 32 | -------------------------------------------------------------------------------- /api-gateway/etc/api-gateway-service.urm.puml: -------------------------------------------------------------------------------- 1 | @startuml 2 | package com.iluwatar.api.gateway { 3 | class ApiGateway { 4 | - imageClient : ImageClient 5 | - priceClient : PriceClient 6 | + ApiGateway() 7 | + getProductDesktop() : DesktopProduct 8 | + getProductMobile() : MobileProduct 9 | } 10 | class App { 11 | + App() 12 | + main(args : String[]) {static} 13 | } 14 | class DesktopProduct { 15 | - imagePath : String 16 | - price : String 17 | + DesktopProduct() 18 | + getImagePath() : String 19 | + getPrice() : String 20 | + setImagePath(imagePath : String) 21 | + setPrice(price : String) 22 | } 23 | interface ImageClient { 24 | + getImagePath() : String {abstract} 25 | } 26 | class ImageClientImpl { 27 | + ImageClientImpl() 28 | + getImagePath() : String 29 | } 30 | class MobileProduct { 31 | - price : String 32 | + MobileProduct() 33 | + getPrice() : String 34 | + setPrice(price : String) 35 | } 36 | interface PriceClient { 37 | + getPrice() : String {abstract} 38 | } 39 | class PriceClientImpl { 40 | + PriceClientImpl() 41 | + getPrice() : String 42 | } 43 | } 44 | ApiGateway --> "-imageClient" ImageClient 45 | ApiGateway --> "-priceClient" PriceClient 46 | ImageClientImpl ..|> ImageClient 47 | PriceClientImpl ..|> PriceClient 48 | @enduml -------------------------------------------------------------------------------- /service-layer/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: pattern 3 | title: Service Layer 4 | folder: service-layer 5 | permalink: /patterns/service-layer/ 6 | pumlid: LOl93SCm3C1MQGUmzUysgY8aAcJ5q96WszVV_aW2V8gHriRb-ZWoPxm07E--Inxrhc2dqv8jEvq3HEl6H8SFNjWs3jcjJSnaju21iG3MSmbnK_mkuwJ_qij7dpNq1m00 7 | categories: Architectural 8 | tags: 9 | - Java 10 | - Difficulty-Intermediate 11 | --- 12 | 13 | ## Intent 14 | Service Layer is an abstraction over domain logic. Typically 15 | applications require multiple kinds of interfaces to the data they store and 16 | logic they implement: data loaders, user interfaces, integration gateways, and 17 | others. Despite their different purposes, these interfaces often need common 18 | interactions with the application to access and manipulate its data and invoke 19 | its business logic. The Service Layer fulfills this role. 20 | 21 | ![alt text](./etc/service-layer.png "Service Layer") 22 | 23 | ## Applicability 24 | Use the Service Layer pattern when 25 | 26 | * you want to encapsulate domain logic under API 27 | * you need to implement multiple interfaces with common logic and data 28 | 29 | ## Credits 30 | 31 | * [Martin Fowler - Service Layer](http://martinfowler.com/eaaCatalog/serviceLayer.html) 32 | * [Patterns of Enterprise Application Architecture](http://www.amazon.com/Patterns-Enterprise-Application-Architecture-Martin/dp/0321127420) 33 | -------------------------------------------------------------------------------- /data-mapper/etc/data-mapper.urm.puml: -------------------------------------------------------------------------------- 1 | @startuml 2 | package com.iluwatar.datamapper { 3 | class App { 4 | - log : Logger {static} 5 | - App() 6 | + main(args : String[]) {static} 7 | } 8 | class Student { 9 | - grade : char 10 | - name : String 11 | - serialVersionUID : long {static} 12 | - studentId : int 13 | + Student(studentId : int, name : String, grade : char) 14 | + equals(inputObject : Object) : boolean 15 | + getGrade() : char 16 | + getName() : String 17 | + getStudentId() : int 18 | + hashCode() : int 19 | + setGrade(grade : char) 20 | + setName(name : String) 21 | + setStudentId(studentId : int) 22 | + toString() : String 23 | } 24 | interface StudentDataMapper { 25 | + delete(Student) {abstract} 26 | + find(int) : Optional {abstract} 27 | + insert(Student) {abstract} 28 | + update(Student) {abstract} 29 | } 30 | class StudentDataMapperImpl { 31 | - students : List 32 | + StudentDataMapperImpl() 33 | + delete(studentToBeDeleted : Student) 34 | + find(studentId : int) : Optional 35 | + getStudents() : List 36 | + insert(studentToBeInserted : Student) 37 | + update(studentToBeUpdated : Student) 38 | } 39 | } 40 | StudentDataMapperImpl --> "-students" Student 41 | StudentDataMapperImpl ..|> StudentDataMapper 42 | @enduml -------------------------------------------------------------------------------- /extension-objects/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: pattern 3 | title: Extension objects 4 | folder: extension-objects 5 | permalink: /patterns/extension-objects/ 6 | categories: Behavioral 7 | tags: 8 | - Java 9 | - Difficulty-Intermediate 10 | --- 11 | 12 | ## Intent 13 | Anticipate that an object’s interface needs to be extended in the future. Additional 14 | interfaces are defined by extension objects. 15 | 16 | ![Extension_objects](./etc/extension_obj.png "Extension objects") 17 | 18 | ## Applicability 19 | Use the Extension Objects pattern when: 20 | 21 | * you need to support the addition of new or unforeseen interfaces to existing classes and you don't want to impact clients that don't need this new interface. Extension Objects lets you keep related operations together by defining them in a separate class 22 | * a class representing a key abstraction plays different roles for different clients. The number of roles the class can play should be open-ended. There is a need to preserve the key abstraction itself. For example, a customer object is still a customer object even if different subsystems view it differently. 23 | * a class should be extensible with new behavior without subclassing from it. 24 | 25 | ## Real world examples 26 | 27 | * [OpenDoc](https://en.wikipedia.org/wiki/OpenDoc) 28 | * [Object Linking and Embedding](https://en.wikipedia.org/wiki/Object_Linking_and_Embedding) 29 | -------------------------------------------------------------------------------- /naked-objects/webapp/ide/intellij/launch/README.txt: -------------------------------------------------------------------------------- 1 | ==== 2 | The MIT License 3 | Copyright (c) 2014-2016 Ilkka Seppälä 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | ==== 23 | 24 | Copy into workspace\.idea\runConfigurations directory, and adjust file paths for Maven tasks. 25 | 26 | -------------------------------------------------------------------------------- /marker/src/main/java/Permission.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License 3 | * Copyright (c) 2014 Ilkka Seppälä 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in 13 | * all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | * THE SOFTWARE. 22 | */ 23 | /** 24 | * Interface without any methods 25 | * Marker interface is based on that assumption 26 | */ 27 | public interface Permission { 28 | } 29 | -------------------------------------------------------------------------------- /event-asynchronous/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: pattern 3 | title: Event-based Asynchronous 4 | folder: event-asynchronous 5 | permalink: /patterns/event-asynchronous/ 6 | categories: Concurrency 7 | tags: 8 | - difficulty-intermediate 9 | - performance 10 | - Java 11 | --- 12 | 13 | ## Intent 14 | The Event-based Asynchronous Pattern makes available the advantages of multithreaded applications while hiding many 15 | of the complex issues inherent in multithreaded design. Using a class that supports this pattern can allow you to: 16 | 17 | 1. Perform time-consuming tasks, such as downloads and database operations, "in the background," without interrupting your application. 18 | 2. Execute multiple operations simultaneously, receiving notifications when each completes. 19 | 3. Wait for resources to become available without stopping ("hanging") your application. 20 | 4. Communicate with pending asynchronous operations using the familiar events-and-delegates model. 21 | 22 | ![alt text](./etc/event-asynchronous.png "Event-based Asynchronous") 23 | 24 | ## Applicability 25 | Use the Event-based Asynchronous pattern(s) when 26 | 27 | * Time-consuming tasks are needed to run in the background without disrupting the current application. 28 | 29 | ## Credits 30 | 31 | * [Event-based Asynchronous Pattern Overview](https://msdn.microsoft.com/en-us/library/wewwczdw%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396) 32 | -------------------------------------------------------------------------------- /memento/etc/memento.urm.puml: -------------------------------------------------------------------------------- 1 | @startuml 2 | package com.iluwatar.memento { 3 | class App { 4 | - LOGGER : Logger {static} 5 | + App() 6 | + main(args : String[]) {static} 7 | } 8 | class Star { 9 | - ageYears : int 10 | - massTons : int 11 | - type : StarType 12 | + Star(startType : StarType, startAge : int, startMass : int) 13 | ~ getMemento() : StarMemento 14 | ~ setMemento(memento : StarMemento) 15 | + timePasses() 16 | + toString() : String 17 | } 18 | -class StarMementoInternal { 19 | - ageYears : int 20 | - massTons : int 21 | - type : StarType 22 | - StarMementoInternal() 23 | + getAgeYears() : int 24 | + getMassTons() : int 25 | + getType() : StarType 26 | + setAgeYears(ageYears : int) 27 | + setMassTons(massTons : int) 28 | + setType(type : StarType) 29 | } 30 | interface StarMemento { 31 | } 32 | enum StarType { 33 | + DEAD {static} 34 | + RED_GIANT {static} 35 | + SUN {static} 36 | + SUPERNOVA {static} 37 | + UNDEFINED {static} 38 | + WHITE_DWARF {static} 39 | - title : String 40 | + toString() : String 41 | + valueOf(name : String) : StarType {static} 42 | + values() : StarType[] {static} 43 | } 44 | } 45 | StarMementoInternal --> "-type" StarType 46 | Star --> "-type" StarType 47 | StarMementoInternal ..+ Star 48 | StarMementoInternal ..|> StarMemento 49 | @enduml -------------------------------------------------------------------------------- /factory-kit/src/main/java/com/iluwatar/factorykit/Weapon.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License 3 | * Copyright (c) 2014-2016 Ilkka Seppälä 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in 13 | * all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | * THE SOFTWARE. 22 | */ 23 | package com.iluwatar.factorykit; 24 | 25 | /** 26 | * Interface representing weapon. 27 | */ 28 | public interface Weapon { 29 | } 30 | -------------------------------------------------------------------------------- /tolerant-reader/etc/tolerant-reader.urm.puml: -------------------------------------------------------------------------------- 1 | @startuml 2 | package com.iluwatar.tolerantreader { 3 | class App { 4 | - LOGGER : Logger {static} 5 | + App() 6 | + main(args : String[]) {static} 7 | } 8 | class RainbowFish { 9 | - age : int 10 | - lengthMeters : int 11 | - name : String 12 | - serialVersionUID : long {static} 13 | - weightTons : int 14 | + RainbowFish(name : String, age : int, lengthMeters : int, weightTons : int) 15 | + getAge() : int 16 | + getLengthMeters() : int 17 | + getName() : String 18 | + getWeightTons() : int 19 | } 20 | class RainbowFishSerializer { 21 | - RainbowFishSerializer() 22 | + readV1(filename : String) : RainbowFish {static} 23 | + writeV1(rainbowFish : RainbowFish, filename : String) {static} 24 | + writeV2(rainbowFish : RainbowFishV2, filename : String) {static} 25 | } 26 | class RainbowFishV2 { 27 | - angry : boolean 28 | - hungry : boolean 29 | - serialVersionUID : long {static} 30 | - sleeping : boolean 31 | + RainbowFishV2(name : String, age : int, lengthMeters : int, weightTons : int) 32 | + RainbowFishV2(name : String, age : int, lengthMeters : int, weightTons : int, sleeping : boolean, hungry : boolean, angry : boolean) 33 | + getAngry() : boolean 34 | + getHungry() : boolean 35 | + getSleeping() : boolean 36 | } 37 | } 38 | RainbowFishV2 --|> RainbowFish 39 | @enduml -------------------------------------------------------------------------------- /double-checked-locking/src/main/java/com/iluwatar/doublechecked/locking/Item.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License 3 | * Copyright (c) 2014-2016 Ilkka Seppälä 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in 13 | * all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | * THE SOFTWARE. 22 | */ 23 | package com.iluwatar.doublechecked.locking; 24 | 25 | /** 26 | * 27 | * Item 28 | * 29 | */ 30 | public class Item { 31 | } 32 | -------------------------------------------------------------------------------- /extension-objects/src/main/java/abstractextensions/UnitExtension.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License 3 | * Copyright (c) 2014 Ilkka Seppälä 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in 13 | * all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | * THE SOFTWARE. 22 | */ 23 | package abstractextensions; 24 | 25 | /** 26 | * Other Extensions will extend this interface 27 | */ 28 | public interface UnitExtension { 29 | } 30 | -------------------------------------------------------------------------------- /layers/src/main/java/com/iluwatar/layers/View.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License 3 | * Copyright (c) 2014-2016 Ilkka Seppälä 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in 13 | * all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | * THE SOFTWARE. 22 | */ 23 | package com.iluwatar.layers; 24 | 25 | /** 26 | * 27 | * View interface 28 | * 29 | */ 30 | public interface View { 31 | 32 | void render(); 33 | 34 | } 35 | -------------------------------------------------------------------------------- /value-object/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: pattern 3 | title: Value Object 4 | folder: value-object 5 | permalink: /patterns/value-object/ 6 | pumlid: LSZ13SCm20NGLTe1RExTXX2KECBOmfza_VRQszDxDnVBNJFiTG9pVOY2dteqdBdbqf3XK4ULqQbPFWmEklZcikjgXvV9W8Olwhn-e9ijjOpjKW4fv2zgHgypktq1 7 | categories: Creational 8 | tags: 9 | - Java 10 | - Difficulty-Beginner 11 | --- 12 | 13 | ## Intent 14 | Provide objects which follow value semantics rather than reference semantics. 15 | This means value objects' equality are not based on identity. Two value objects are 16 | equal when they have the same value, not necessarily being the same object. 17 | 18 | ![alt text](./etc/value-object.png "Value Object") 19 | 20 | ## Applicability 21 | Use the Value Object when 22 | 23 | * you need to measure the objects' equality based on the objects' value 24 | 25 | ## Real world examples 26 | 27 | * [java.util.Optional](https://docs.oracle.com/javase/8/docs/api/java/util/Optional.html) 28 | * [java.time.LocalDate](https://docs.oracle.com/javase/8/docs/api/java/time/LocalDate.html) 29 | * [joda-time, money, beans](http://www.joda.org/) 30 | 31 | ## Credits 32 | 33 | * [Patterns of Enterprise Application Architecture](http://www.martinfowler.com/books/eaa.html) 34 | * [VALJOs - Value Java Objects : Stephen Colebourne's blog](http://blog.joda.org/2014/03/valjos-value-java-objects.html) 35 | * [Value Object : Wikipedia](https://en.wikipedia.org/wiki/Value_object) 36 | -------------------------------------------------------------------------------- /monad/src/main/java/com/iluwatar/monad/Sex.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License 3 | * Copyright (c) 2014-2016 Ilkka Seppälä 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in 13 | * all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | * THE SOFTWARE. 22 | */ 23 | package com.iluwatar.monad; 24 | 25 | /** 26 | * Enumeration of Types of Sex 27 | */ 28 | public enum Sex { 29 | MALE, FEMALE 30 | } 31 | -------------------------------------------------------------------------------- /repository/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: pattern 3 | title: Repository 4 | folder: repository 5 | permalink: /patterns/repository/ 6 | pumlid: JSV13OCm30NGLM00udktCS42eyI9xE-YRjyUUtjlLQij3qblomNCU14vF-LKNBbdYDTX44EfevEsV1ZiTFERjqD2Jzic0-8Mr3b-89SvGZ7yGuBwrvBUoypUlW00 7 | categories: Persistence Tier 8 | tags: 9 | - Java 10 | - Difficulty-Intermediate 11 | - Spring 12 | --- 13 | 14 | ## Intent 15 | Repository layer is added between the domain and data mapping 16 | layers to isolate domain objects from details of the database access code and 17 | to minimize scattering and duplication of query code. The Repository pattern is 18 | especially useful in systems where number of domain classes is large or heavy 19 | querying is utilized. 20 | 21 | ![alt text](./etc/repository.png "Repository") 22 | 23 | ## Applicability 24 | Use the Repository pattern when 25 | 26 | * the number of domain objects is large 27 | * you want to avoid duplication of query code 28 | * you want to keep the database querying code in single place 29 | * you have multiple data sources 30 | 31 | ## Real world examples 32 | 33 | * [Spring Data](http://projects.spring.io/spring-data/) 34 | 35 | ## Credits 36 | 37 | * [Don’t use DAO, use Repository](http://thinkinginobjects.com/2012/08/26/dont-use-dao-use-repository/) 38 | * [Advanced Spring Data JPA - Specifications and Querydsl](https://spring.io/blog/2011/04/26/advanced-spring-data-jpa-specifications-and-querydsl/) 39 | -------------------------------------------------------------------------------- /callback/src/main/java/com/iluwatar/callback/Callback.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License 3 | * Copyright (c) 2014-2016 Ilkka Seppälä 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in 13 | * all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | * THE SOFTWARE. 22 | */ 23 | package com.iluwatar.callback; 24 | 25 | /** 26 | * 27 | * Callback interface 28 | * 29 | */ 30 | public interface Callback { 31 | 32 | void call(); 33 | } 34 | -------------------------------------------------------------------------------- /proxy/src/main/java/com/iluwatar/proxy/WizardTower.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License 3 | * Copyright (c) 2014-2016 Ilkka Seppälä 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in 13 | * all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | * THE SOFTWARE. 22 | */ 23 | package com.iluwatar.proxy; 24 | 25 | /** 26 | * WizardTower interface 27 | */ 28 | public interface WizardTower { 29 | 30 | void enter(Wizard wizard); 31 | } 32 | -------------------------------------------------------------------------------- /factory-kit/src/main/java/com/iluwatar/factorykit/WeaponType.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License 3 | * Copyright (c) 2014-2016 Ilkka Seppälä 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in 13 | * all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | * THE SOFTWARE. 22 | */ 23 | package com.iluwatar.factorykit; 24 | 25 | /** 26 | * Enumerates {@link Weapon} types 27 | */ 28 | public enum WeaponType { 29 | SWORD, AXE, BOW, SPEAR 30 | } 31 | -------------------------------------------------------------------------------- /monad/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: pattern 3 | title: Monad 4 | folder: monad 5 | permalink: /patterns/monad/ 6 | pumlid: 9SR13SCm20NGLPe1OkxTXjWeSMMm1Pza_LRgExsjMntP97syBc35cyZvAMV7bKU6U9q6CPGwbVh8Xy5E7xvvRnBzj7qn86v1ol4BwJHk9AZ_bNGjAtLy0G00 7 | categories: Other 8 | tags: 9 | - Java 10 | - Difficulty-Expert 11 | - Functional 12 | --- 13 | 14 | ## Intent 15 | 16 | Monad pattern based on monad from linear algebra represents the way of chaining operations 17 | together step by step. Binding functions can be described as passing one's output to another's input 18 | basing on the 'same type' contract. Formally, monad consists of a type constructor M and two 19 | operations: 20 | bind - that takes monadic object and a function from plain object to monadic value and returns monadic value 21 | return - that takes plain type object and returns this object wrapped in a monadic value. 22 | 23 | ![alt text](./etc/monad.png "Monad") 24 | 25 | ## Applicability 26 | 27 | Use the Monad in any of the following situations 28 | 29 | * when you want to chain operations easily 30 | * when you want to apply each function regardless of the result of any of them 31 | 32 | ## Credits 33 | 34 | * [Design Pattern Reloaded by Remi Forax](https://youtu.be/-k2X7guaArU) 35 | * [Brian Beckman: Don't fear the Monad](https://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-Dont-fear-the-Monads) 36 | * [Monad on Wikipedia](https://en.wikipedia.org/wiki/Monad_(functional_programming)) -------------------------------------------------------------------------------- /queue-load-leveling/src/main/java/com/iluwatar/queue/load/leveling/Task.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License 3 | * Copyright (c) 2014 Ilkka Seppälä 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in 13 | * all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | * THE SOFTWARE. 22 | */ 23 | package com.iluwatar.queue.load.leveling; 24 | /** 25 | * Task Interface. 26 | * 27 | */ 28 | public interface Task { 29 | void submit(Message msg); 30 | } 31 | -------------------------------------------------------------------------------- /iterator/src/main/java/com/iluwatar/iterator/ItemType.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License 3 | * Copyright (c) 2014-2016 Ilkka Seppälä 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in 13 | * all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | * THE SOFTWARE. 22 | */ 23 | package com.iluwatar.iterator; 24 | 25 | /** 26 | * 27 | * ItemType enumeration 28 | * 29 | */ 30 | public enum ItemType { 31 | 32 | ANY, WEAPON, RING, POTION 33 | 34 | } 35 | -------------------------------------------------------------------------------- /exclude-pmd.properties: -------------------------------------------------------------------------------- 1 | # 2 | # The MIT License 3 | # Copyright (c) 2014-2016 Ilkka Seppälä 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in 13 | # all copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | # THE SOFTWARE. 22 | # 23 | 24 | com.iluwatar.servicelayer.common.BaseEntity=UnusedPrivateField 25 | com.iluwatar.doublechecked.locking.App=EmptyStatementNotInLoop,EmptyWhileStmt 26 | com.iluwatar.doublechecked.locking.InventoryTest=EmptyStatementNotInLoop,EmptyWhileStmt 27 | -------------------------------------------------------------------------------- /factory-method/src/main/java/com/iluwatar/factory/method/Weapon.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License 3 | * Copyright (c) 2014-2016 Ilkka Seppälä 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in 13 | * all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | * THE SOFTWARE. 22 | */ 23 | package com.iluwatar.factory.method; 24 | 25 | /** 26 | * Weapon interface. 27 | */ 28 | public interface Weapon { 29 | 30 | WeaponType getWeaponType(); 31 | 32 | } 33 | -------------------------------------------------------------------------------- /abstract-factory/src/main/java/com/iluwatar/abstractfactory/Army.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License 3 | * Copyright (c) 2014-2016 Ilkka Seppälä 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in 13 | * all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | * THE SOFTWARE. 22 | */ 23 | package com.iluwatar.abstractfactory; 24 | 25 | /** 26 | * 27 | * Army interface 28 | * 29 | */ 30 | public interface Army { 31 | 32 | String getDescription(); 33 | } 34 | -------------------------------------------------------------------------------- /abstract-factory/src/main/java/com/iluwatar/abstractfactory/King.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License 3 | * Copyright (c) 2014-2016 Ilkka Seppälä 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in 13 | * all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | * THE SOFTWARE. 22 | */ 23 | package com.iluwatar.abstractfactory; 24 | 25 | /** 26 | * 27 | * King interface 28 | * 29 | */ 30 | public interface King { 31 | 32 | String getDescription(); 33 | } 34 | -------------------------------------------------------------------------------- /aggregator-microservices/etc/aggregator-service.urm.puml: -------------------------------------------------------------------------------- 1 | @startuml 2 | package com.iluwatar.aggregator.microservices { 3 | class Aggregator { 4 | - informationClient : ProductInformationClient 5 | - inventoryClient : ProductInventoryClient 6 | + Aggregator() 7 | + getProduct() : Product 8 | } 9 | class App { 10 | + App() 11 | + main(args : String[]) {static} 12 | } 13 | class Product { 14 | - productInventories : int 15 | - title : String 16 | + Product() 17 | + getProductInventories() : int 18 | + getTitle() : String 19 | + setProductInventories(productInventories : int) 20 | + setTitle(title : String) 21 | } 22 | interface ProductInformationClient { 23 | + getProductTitle() : String {abstract} 24 | } 25 | class ProductInformationClientImpl { 26 | - LOGGER : Logger {static} 27 | + ProductInformationClientImpl() 28 | + getProductTitle() : String 29 | } 30 | interface ProductInventoryClient { 31 | + getProductInventories() : int {abstract} 32 | } 33 | class ProductInventoryClientImpl { 34 | - LOGGER : Logger {static} 35 | + ProductInventoryClientImpl() 36 | + getProductInventories() : int 37 | } 38 | } 39 | Aggregator --> "-informationClient" ProductInformationClient 40 | Aggregator --> "-inventoryClient" ProductInventoryClient 41 | ProductInformationClientImpl ..|> ProductInformationClient 42 | ProductInventoryClientImpl ..|> ProductInventoryClient 43 | @enduml -------------------------------------------------------------------------------- /marker/src/test/java/AppTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License 3 | * Copyright (c) 2014 Ilkka Seppälä 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in 13 | * all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | * THE SOFTWARE. 22 | */ 23 | import org.junit.Test; 24 | 25 | /** 26 | * Application test 27 | */ 28 | public class AppTest { 29 | 30 | @Test 31 | public void test() { 32 | String[] args = {}; 33 | App.main(args); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /abstract-factory/src/main/java/com/iluwatar/abstractfactory/Castle.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License 3 | * Copyright (c) 2014-2016 Ilkka Seppälä 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in 13 | * all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | * THE SOFTWARE. 22 | */ 23 | package com.iluwatar.abstractfactory; 24 | 25 | /** 26 | * 27 | * Castle interface 28 | * 29 | */ 30 | public interface Castle { 31 | 32 | String getDescription(); 33 | } 34 | -------------------------------------------------------------------------------- /extension-objects/src/main/java/abstractextensions/SoldierExtension.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License 3 | * Copyright (c) 2014 Ilkka Seppälä 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in 13 | * all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | * THE SOFTWARE. 22 | */ 23 | package abstractextensions; 24 | 25 | /** 26 | * Interface with their method 27 | */ 28 | public interface SoldierExtension extends UnitExtension { 29 | void soldierReady(); 30 | } 31 | -------------------------------------------------------------------------------- /flux/src/main/java/com/iluwatar/flux/action/ActionType.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License 3 | * Copyright (c) 2014-2016 Ilkka Seppälä 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in 13 | * all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | * THE SOFTWARE. 22 | */ 23 | package com.iluwatar.flux.action; 24 | 25 | /** 26 | * 27 | * Types of actions. 28 | * 29 | */ 30 | public enum ActionType { 31 | 32 | MENU_ITEM_SELECTED, CONTENT_CHANGED; 33 | 34 | } 35 | -------------------------------------------------------------------------------- /iterator/etc/iterator.urm.puml: -------------------------------------------------------------------------------- 1 | @startuml 2 | package com.iluwatar.iterator { 3 | class App { 4 | - LOGGER : Logger {static} 5 | + App() 6 | + main(args : String[]) {static} 7 | } 8 | class Item { 9 | - name : String 10 | - type : ItemType 11 | + Item(type : ItemType, name : String) 12 | + getType() : ItemType 13 | + setType(type : ItemType) 14 | + toString() : String 15 | } 16 | interface ItemIterator { 17 | + hasNext() : boolean {abstract} 18 | + next() : Item {abstract} 19 | } 20 | enum ItemType { 21 | + ANY {static} 22 | + POTION {static} 23 | + RING {static} 24 | + WEAPON {static} 25 | + valueOf(name : String) : ItemType {static} 26 | + values() : ItemType[] {static} 27 | } 28 | class TreasureChest { 29 | - items : List 30 | + TreasureChest() 31 | + getItems() : List 32 | ~ iterator(itemType : ItemType) : ItemIterator 33 | } 34 | class TreasureChestItemIterator { 35 | - chest : TreasureChest 36 | - idx : int 37 | - type : ItemType 38 | + TreasureChestItemIterator(chest : TreasureChest, type : ItemType) 39 | - findNextIdx() : int 40 | + hasNext() : boolean 41 | + next() : Item 42 | } 43 | } 44 | Item --> "-type" ItemType 45 | TreasureChest --> "-items" Item 46 | TreasureChestItemIterator --> "-type" ItemType 47 | TreasureChestItemIterator --> "-chest" TreasureChest 48 | TreasureChestItemIterator ..|> ItemIterator 49 | @enduml -------------------------------------------------------------------------------- /memento/src/main/java/com/iluwatar/memento/StarMemento.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License 3 | * Copyright (c) 2014-2016 Ilkka Seppälä 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in 13 | * all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | * THE SOFTWARE. 22 | */ 23 | package com.iluwatar.memento; 24 | 25 | /** 26 | * 27 | * External interface to memento. 28 | * 29 | */ 30 | public interface StarMemento { 31 | 32 | } 33 | -------------------------------------------------------------------------------- /semaphore/etc/semaphore.urm.puml: -------------------------------------------------------------------------------- 1 | @startuml 2 | package com.iluwatar.semaphore { 3 | class App { 4 | + App() 5 | + main(args : String[]) {static} 6 | } 7 | class Fruit { 8 | - type : FruitType 9 | + Fruit(type : FruitType) 10 | + getType() : FruitType 11 | + toString() : String 12 | } 13 | enum FruitType { 14 | + APPLE {static} 15 | + LEMON {static} 16 | + ORANGE {static} 17 | + valueOf(name : String) : FruitType {static} 18 | + values() : FruitType[] {static} 19 | } 20 | class FruitBowl { 21 | - fruit : List 22 | + FruitBowl() 23 | + countFruit() : int 24 | + put(f : Fruit) 25 | + take() : Fruit 26 | + toString() : String 27 | } 28 | class FruitShop { 29 | - available : boolean[] 30 | - bowls : FruitBowl[] 31 | - semaphore : Semaphore 32 | + FruitShop() 33 | + countFruit() : int 34 | + returnBowl(bowl : FruitBowl) 35 | + takeBowl() : FruitBowl 36 | } 37 | interface Lock { 38 | + acquire() {abstract} 39 | + release() {abstract} 40 | } 41 | class Semaphore { 42 | - counter : int 43 | - licenses : int 44 | + Semaphore(licenses : int) 45 | + acquire() 46 | + getAvailableLicenses() : int 47 | + getNumLicenses() : int 48 | + release() 49 | } 50 | } 51 | FruitType ..+ Fruit 52 | Fruit --> "-type" FruitType 53 | FruitShop --> "-semaphore" Semaphore 54 | FruitBowl --> "-fruit" Fruit 55 | Semaphore ..|> Lock 56 | @enduml -------------------------------------------------------------------------------- /business-delegate/src/main/java/com/iluwatar/business/delegate/ServiceType.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License 3 | * Copyright (c) 2014-2016 Ilkka Seppälä 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in 13 | * all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | * THE SOFTWARE. 22 | */ 23 | package com.iluwatar.business.delegate; 24 | 25 | /** 26 | * 27 | * Enumeration for service types 28 | * 29 | */ 30 | public enum ServiceType { 31 | 32 | EJB, JMS; 33 | } 34 | -------------------------------------------------------------------------------- /chain/src/main/java/com/iluwatar/chain/RequestType.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License 3 | * Copyright (c) 2014-2016 Ilkka Seppälä 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in 13 | * all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | * THE SOFTWARE. 22 | */ 23 | package com.iluwatar.chain; 24 | 25 | /** 26 | * 27 | * RequestType enumeration 28 | * 29 | */ 30 | public enum RequestType { 31 | 32 | DEFEND_CASTLE, TORTURE_PRISONER, COLLECT_TAX 33 | 34 | } 35 | -------------------------------------------------------------------------------- /dependency-injection/src/main/java/com/iluwatar/dependency/injection/Wizard.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License 3 | * Copyright (c) 2014-2016 Ilkka Seppälä 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in 13 | * all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | * THE SOFTWARE. 22 | */ 23 | package com.iluwatar.dependency.injection; 24 | 25 | /** 26 | * 27 | * Wizard interface 28 | * 29 | */ 30 | public interface Wizard { 31 | 32 | void smoke(); 33 | 34 | } 35 | -------------------------------------------------------------------------------- /extension-objects/src/main/java/abstractextensions/SergeantExtension.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License 3 | * Copyright (c) 2014 Ilkka Seppälä 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in 13 | * all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | * THE SOFTWARE. 22 | */ 23 | package abstractextensions; 24 | 25 | /** 26 | * Interface with their method 27 | */ 28 | public interface SergeantExtension extends UnitExtension { 29 | 30 | void sergeantReady(); 31 | } 32 | -------------------------------------------------------------------------------- /flyweight/src/main/java/com/iluwatar/flyweight/Potion.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License 3 | * Copyright (c) 2014-2016 Ilkka Seppälä 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in 13 | * all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | * THE SOFTWARE. 22 | */ 23 | package com.iluwatar.flyweight; 24 | 25 | /** 26 | * 27 | * Interface for Potions. 28 | * 29 | */ 30 | public interface Potion { 31 | 32 | void drink(); 33 | } 34 | -------------------------------------------------------------------------------- /extension-objects/src/main/java/abstractextensions/CommanderExtension.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License 3 | * Copyright (c) 2014 Ilkka Seppälä 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in 13 | * all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | * THE SOFTWARE. 22 | */ 23 | package abstractextensions; 24 | 25 | /** 26 | * Interface with their method 27 | */ 28 | public interface CommanderExtension extends UnitExtension { 29 | 30 | void commanderReady(); 31 | } 32 | --------------------------------------------------------------------------------