- properly categorize all patterns
- remove pattern list from readme
- minor fixes to readme
- removed "introduction" because its not a pattern and an error i
committed some time ago
This commit is contained in:
Markus 2015-08-20 21:40:07 +02:00
parent 9691a371e6
commit 5ce932ceb7
58 changed files with 129 additions and 265 deletions

148
README.md
View File

@ -1,4 +1,8 @@
# Design pattern samples in Java.
<!-- the line below needs to be an empty line C: (its because kramdown isnt
that smart and dearly wants an empty line before a heading to be able to
display it as such, e.g. website) -->
# Design pattern samples in Java
[![Join the chat at https://gitter.im/iluwatar/java-design-patterns](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/iluwatar/java-design-patterns?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
@ -7,24 +11,19 @@
src="https://scan.coverity.com/projects/5634/badge.svg"/>
</a>
<a name="top"/>
#### Browse and view all of the patterns on our Website: [iluwatar.github.io/java-design-patterns/](https://iluwatar.github.io/java-design-patterns/)
<a name="top"/>
# <a name="toc">Table of Contents</a>
- <a href="#introduction">Introduction</a>
- <a href="#list-of-design-patterns">List of Design Patterns</a>
- <a href="#creational-patterns">Creational Patterns</a>
- <a href="#structural-patterns">Structural Patterns</a>
- <a href="#behavioral-patterns">Behavioral Patterns</a>
- <a href="#concurrency-patterns">Concurrency Patterns</a>
- <a href="#presentation-tier-patterns">Presentation Tier Patterns</a>
- <a href="#business-tier-patterns">Business Tier Patterns</a>
- <a href="#architectural-patterns">Architectural Patterns</a>
- <a href="#integration-patterns">Integration Patterns</a>
- <a href="#idioms">Idioms</a>
- <a href="#faq">Frequently Asked Questions</a>
- <a href="#how-to-contribute">How to contribute</a>
- <a href="#versioning">Versioning</a>
- <a href="#credits">Credits</a>
- <a href="#license">License</a>
## <a name="introduction">Introduction</a>
@ -38,119 +37,6 @@ Reusing design patterns helps to prevent subtle issues that can cause major
problems, and it also improves code readability for coders and architects who
are familiar with the patterns.
## <a name="list-of-design-patterns">List of Design Patterns</a> [&#8593;](#top)
### <a name="creational-patterns">Creational Patterns</a> [&#8593;](#top)
Creational design patterns abstract the instantiation process. They help make a
system independent of how its objects are created, composed, and represented.
* [Abstract Factory](#abstract-factory)
* [Builder](#builder)
* [Factory Method](#factory-method)
* [Prototype](#prototype)
* [Property](#property)
* [Singleton](#singleton)
* [Step Builder](#step-builder)
* [Multiton](#multiton)
* [Object Pool](#object-pool)
### <a name="structural-patterns">Structural Patterns</a> [&#8593;](#top)
Structural patterns are concerned with how classes and objects are composed to
form larger structures.
* [Adapter](#adapter)
* [Bridge](#bridge)
* [Composite](#composite)
* [Decorator](#decorator)
* [Facade](#facade)
* [Flyweight](#flyweight)
* [Proxy](#proxy)
* [Service Locator](#service-locator)
* [Servant](#servant)
* [Event Aggregator](#event-aggregator)
### <a name="behavioral-patterns">Behavioral Patterns</a> [&#8593;](#top)
Behavioral patterns are concerned with algorithms and the assignment of
responsibilities between objects.
* [Chain of responsibility](#chain-of-responsibility)
* [Command](#command)
* [Interpreter](#interpreter)
* [Iterator](#iterator)
* [Mediator](#mediator)
* [Memento](#memento)
* [Observer](#observer)
* [State](#state)
* [Strategy](#strategy)
* [Template method](#template-method)
* [Visitor](#visitor)
* [Null Object](#null-object)
* [Intercepting Filter](#intercepting-filter)
* [Specification](#specification)
* [Dependency Injection](#dependency-injection)
### <a name="concurrency-patterns">Concurrency Patterns</a> [&#8593;](#top)
Concurrency patterns are those types of design patterns that deal with the
multi-threaded programming paradigm.
* [Double Checked Locking](#double-checked-locking)
* [Thread Pool](#thread-pool)
* [Async Method Invocation](#async-method-invocation)
* [Half-Sync/Half-Async](#half-sync-half-async)
### <a name="presentation-tier-patterns">Presentation Tier Patterns</a> [&#8593;](#top)
Presentation Tier patterns are the top-most level of the application, this is
concerned with translating tasks and results to something the user can
understand.
* [Model-View-Controller](#model-view-controller)
* [Model-View-Presenter](#model-view-presenter)
* [Flux](#flux)
* [Front Controller](#front-controller)
### <a name="business-tier-patterns">Business Tier Patterns</a> [&#8593;](#top)
* [Business Delegate](#business-delegate)
### <a name="architectural-patterns">Architectural Patterns</a> [&#8593;](#top)
An architectural pattern is a general, reusable solution to a commonly occurring
problem in software architecture within a given context.
* [Data Access Object](#dao)
* [Service Layer](#service-layer)
* [Naked Objects](#naked-objects)
* [Repository](#repository)
### <a name="integration-patterns">Integration Patterns</a> [&#8593;](#top)
Integration patterns are concerned with how software applications communicate
and exchange data.
* [Tolerant Reader](#tolerant-reader)
### <a name="idioms">Idioms</a> [&#8593;](#top)
A programming idiom is a means of expressing a recurring construct in one or
more programming languages. Generally speaking, a programming idiom is an
expression of a simple task, algorithm, or data structure that is not a built-in
feature in the programming language being used, or, conversely, the use of an
unusual or notable feature that is built into a programming language. What
distinguishes idioms from patterns is generally the size, the idioms tend to be
something small while the patterns are larger.
* [Execute Around](#execute-around)
* [Poison Pill](#poison-pill)
* [Callback](#callback)
* [Lazy Loading](#lazy-loading)
* [Double Dispatch](#double-dispatch)
* [Resource Acquisition Is Initialization](#resource-acquisition-is-initialization)
* [Private Class Data](#private-class-data)
# <a name="faq">Frequently asked questions</a> [&#8593;](#top)
@ -225,16 +111,16 @@ Flyweight.
* src (the source code of the pattern)
* index.md (the description of the pattern)
* pom.xml (the maven pom.xml)
3. Implement the code changes in your fork. Remember to add sufficient comments
4. Implement the code changes in your fork. Remember to add sufficient comments
documenting the implementation. Reference the issue id e.g. #52 in your
commit messages.
4. Format the code according to [Google Java Style Guide](https://google.github.io/styleguide/javaguide.html)
5. Format the code according to [Google Java Style Guide](https://google.github.io/styleguide/javaguide.html)
* [Eclipse configuration](https://github.com/google/styleguide/blob/gh-pages/eclipse-java-google-style.xml)
* [IntelliJ configuration](https://github.com/google/styleguide/blob/gh-pages/intellij-java-google-style.xml)
5. Create a simple class diagram from your example code and put it inside of the etc folder.
6. Add description of the pattern in index.md and link to the class diagram.
6. Create a simple class diagram from your example code and put it inside of the etc folder.
7. Add description of the pattern in index.md and link to the class diagram.
(Attention, all internal links must be relative to the pattern subdirectory, else the links dont link properly on the website)
7. Create a pull request.
8. Create a pull request.
**Structure of the index.md file**

View File

@ -3,10 +3,8 @@ layout: pattern
title: Abstract Factory
folder: abstract-factory
permalink: /patterns/abstract-factory/
categories:
- pattern_cat
- creational
tags: pattern_tag
categories: Creational
tags: Java
---
**Intent:** Provide an interface for creating families of related or dependent

View File

@ -3,8 +3,8 @@ layout: pattern
title: Adapter
folder: adapter
permalink: /patterns/adapter/
categories: structural
tags: pattern_tag
categories: Structural
tags: Java
---
**Intent:** Convert the interface of a class into another interface the clients

View File

@ -3,8 +3,8 @@ layout: pattern
title: Async Method Invocation
folder: async-method-invocation
permalink: /patterns/async-method-invocation/
categories: concurrency
tags: pattern_tag
categories: Concurrency
tags: Java
---
**Intent:** Asynchronous method invocation is pattern where the calling thread

View File

@ -3,8 +3,8 @@ layout: pattern
title: Bridge
folder: bridge
permalink: /patterns/bridge/
categories: structural
tags: pattern_tag
categories: Structural
tags: Java
---
**Intent:** Decouple an abstraction from its implementation so that the two can

View File

@ -3,8 +3,8 @@ layout: pattern
title: Builder
folder: builder
permalink: /patterns/builder/
categories: creational
tags: pattern_tag
categories: Creational
tags: Java
---
**Intent:** Separate the construction of a complex object from its

View File

@ -3,8 +3,8 @@ layout: pattern
title: Business Delegate
folder: business-delegate
permalink: /patterns/business-delegate/
categories: business_tier
tags: pattern_tag
categories: Business Tier
tags: Java
---
**Intent:** The Business Delegate pattern adds an abstraction layer between

View File

@ -3,8 +3,8 @@ layout: pattern
title: Callback
folder: callback
permalink: /patterns/callback/
categories: pattern_cat
tags: pattern_tag
categories: Other
tags: Java
---
**Intent:** Callback is a piece of executable code that is passed as an

View File

@ -3,8 +3,8 @@ layout: pattern
title: Chain of responsibility
folder: chain-of-responsibility
permalink: /patterns/chain-of-responsibility/
categories: behavioral
tags: pattern_tag
categories: Behavioral
tags: Java
---
**Intent:** Avoid coupling the sender of a request to its receiver by giving

View File

@ -3,8 +3,8 @@ layout: pattern
title: Command
folder: command
permalink: /patterns/command/
categories: behavioral
tags: pattern_tag
categories: Behavioral
tags: Java
---
**Intent:** Encapsulate a request as an object, thereby letting you

View File

@ -3,8 +3,8 @@ layout: pattern
title: Composite
folder: composite
permalink: /patterns/composite/
categories: pattern_cat
tags: pattern_tag
categories: Structural
tags: Java
---
**Intent:** Compose objects into tree structures to represent part-whole

View File

@ -3,8 +3,8 @@ layout: pattern
title: Data Access Object
folder: dao
permalink: /patterns/dao/
categories: architectural
tags: pattern_tag
categories: Architectural
tags: Java
---
**Intent:** Object provides an abstract interface to some type of database or

View File

@ -3,8 +3,8 @@ layout: pattern
title: Decorator
folder: decorator
permalink: /patterns/decorator/
categories: structural
tags: pattern_tag
categories: Structural
tags: Java
---
**Intent:** Attach additional responsibilities to an object dynamically.

View File

@ -3,8 +3,8 @@ layout: pattern
title: Dependency Injection
folder: dependency-injection
permalink: /patterns/dependency-injection/
categories: behavioral
tags: pattern_tag
categories: Behavioral
tags: Java
---
**Intent:** Dependency Injection is a software design pattern in which one or

View File

@ -3,8 +3,8 @@ layout: pattern
title: Double Checked Locking
folder: double-checked-locking
permalink: /patterns/double-checked-locking/
categories: concurrency
tags: pattern_tag
categories: Concurrency
tags: Java
---
**Intent:** Reduce the overhead of acquiring a lock by first testing the

View File

@ -3,8 +3,8 @@ layout: pattern
title: Double Dispatch
folder: double-dispatch
permalink: /patterns/double-dispatch/
categories: pattern_cat
tags: pattern_tag
categories: Other
tags: Java
---
**Intent:** Double Dispatch pattern is a way to create maintainable dynamic

View File

@ -3,8 +3,8 @@ layout: pattern
title: Event Aggregator
folder: event-aggregator
permalink: /patterns/event-aggregator/
categories: structural
tags: pattern_tag
categories: Structural
tags: Java
---
**Intent:** A system with lots of objects can lead to complexities when a

View File

@ -3,8 +3,8 @@ layout: pattern
title: Execute Around
folder: execute-around
permalink: /patterns/execute-around/
categories: pattern_cat
tags: pattern_tag
categories: Other
tags: Java
---
**Intent:** Execute Around idiom frees the user from certain actions that

View File

@ -3,8 +3,8 @@ layout: pattern
title: Facade
folder: facade
permalink: /patterns/facade/
categories: structural
tags: pattern_tag
categories: Structural
tags: Java
---
**Intent:** Provide a unified interface to a set of interfaces in a subsystem.

View File

@ -3,8 +3,8 @@ layout: pattern
title: Factory Method
folder: factory-method
permalink: /patterns/factory-method/
categories: creational
tags: pattern_tag
categories: Creational
tags: Java
---
**Intent:** Define an interface for creating an object, but let subclasses

View File

@ -3,8 +3,8 @@ layout: pattern
title: Flux
folder: flux
permalink: /patterns/flux/
categories: presentation_tier
tags: pattern_tag
categories: Presentation Tier
tags: Java
---
**Intent:** Flux eschews MVC in favor of a unidirectional data flow. When a

View File

@ -3,8 +3,8 @@ layout: pattern
title: Flyweight
folder: flyweight
permalink: /patterns/flyweight/
categories: structural
tags: pattern_tag
categories: Structural
tags: Java
---
**Intent:** Use sharing to support large numbers of fine-grained objects

View File

@ -3,8 +3,8 @@ layout: pattern
title: Front Controller
folder: front-controller
permalink: /patterns/front-controller/
categories: presentation_tier
tags: pattern_tag
categories: Presentation Tier
tags: Java
---
**Intent:** Introduce a common handler for all requests for a web site. This

View File

@ -3,8 +3,8 @@ layout: pattern
title: Half-Sync/Half-Async
folder: half-sync-half-async
permalink: /patterns/half-sync-half-async/
categories: concurrency
tags: pattern_tag
categories: Concurrency
tags: Java
---
**Intent:** The Half-Sync/Half-Async pattern decouples synchronous I/O from

View File

@ -3,8 +3,8 @@ layout: pattern
title: Intercepting Filter
folder: intercepting-filter
permalink: /patterns/intercepting-filter/
categories: behavioral
tags: pattern_tag
categories: Behavioral
tags: Java
---
**Intent:** Provide pluggable filters to conduct necessary pre-processing and

View File

@ -3,8 +3,8 @@ layout: pattern
title: Interpreter
folder: interpreter
permalink: /patterns/interpreter/
categories: behavioral
tags: pattern_tag
categories: Behavioral
tags: Java
---
**Intent:** Given a language, define a representation for its grammar along

View File

@ -1,20 +0,0 @@
---
layout: pattern
title: Introduction
folder: introduction
permalink: /patterns/introduction/
permalink: /patterns/introduction/
categories: pattern_cat
tags: pattern_tag
---
Design patterns are formalized best practices that the programmer can use to
solve common problems when designing an application or system.
Design patterns can speed up the development process by providing tested, proven
development paradigms.
Reusing design patterns helps to prevent subtle issues that can cause major
problems, and it also improves code readability for coders and architects who
are familiar with the patterns.

View File

@ -3,8 +3,8 @@ layout: pattern
title: Iterator
folder: iterator
permalink: /patterns/iterator/
categories: behavioral
tags: pattern_tag
categories: Behavioral
tags: Java
---
**Intent:** Provide a way to access the elements of an aggregate object

View File

@ -3,8 +3,8 @@ layout: pattern
title: Layers
folder: layers
permalink: /patterns/layers/
categories: architectural
tags: pattern_tag
categories: Architectural
tags: Java
---
**Intent:** Layers is an architectural style where software responsibilities are

View File

@ -3,8 +3,8 @@ layout: pattern
title: Lazy Loading
folder: lazy-loading
permalink: /patterns/lazy-loading/
categories: pattern_cat
tags: pattern_tag
categories: Other
tags: Java
---
**Intent:** Lazy loading is a design pattern commonly used to defer

View File

@ -3,8 +3,8 @@ layout: pattern
title: Mediator
folder: mediator
permalink: /patterns/mediator/
categories: behavioral
tags: pattern_tag
categories: Behavioral
tags: Java
---
**Intent:** Define an object that encapsulates how a set of objects interact.

View File

@ -3,8 +3,8 @@ layout: pattern
title: Memento
folder: memento
permalink: /patterns/memento/
categories: behavioral
tags: pattern_tag
categories: Behavioral
tags: Java
---
**Intent:** Without violating encapsulation, capture and externalize an

View File

@ -3,8 +3,8 @@ layout: pattern
title: Model-View-Controller
folder: model-view-controller
permalink: /patterns/model-view-controller/
categories: presentation_tier
tags: pattern_tag
categories: Presentation Tier
tags: Java
---
**Intent:** Separate the user interface into three interconnected components:

View File

@ -3,8 +3,8 @@ layout: pattern
title: Model-View-Presenter
folder: model-view-presenter
permalink: /patterns/model-view-presenter/
categories: presentation_tier
tags: pattern_tag
categories: Presentation Tier
tags: Java
---
**Intent:** Apply a "Separation of Concerns" principle in a way that allows

View File

@ -3,8 +3,8 @@ layout: pattern
title: Multiton
folder: multiton
permalink: /patterns/multiton/
categories: creational
tags: pattern_tag
categories: Creational
tags: Java
---
**Intent:** Ensure a class only has limited number of instances, and provide a

View File

@ -3,8 +3,8 @@ layout: pattern
title: Naked Objects
folder: naked-objects
permalink: /patterns/naked-objects/
categories: architectural
tags: pattern_tag
categories: Architectural
tags: Java
---
**Intent:** The Naked Objects architectural pattern is well suited for rapid

View File

@ -3,8 +3,8 @@ layout: pattern
title: Null Object
folder: null-object
permalink: /patterns/null-object/
categories: behavioral
tags: pattern_tag
categories: Behavioral
tags: Java
---
**Intent:** In most object-oriented languages, such as Java or C#, references

View File

@ -3,8 +3,8 @@ layout: pattern
title: Object Pool
folder: object-pool
permalink: /patterns/object-pool/
categories: creational
tags: pattern_tag
categories: Creational
tags: Java
---
**Intent:** When objects are expensive to create and they are needed only for

View File

@ -3,8 +3,8 @@ layout: pattern
title: Observer
folder: observer
permalink: /patterns/observer/
categories: behavioral
tags: pattern_tag
categories: Behavioral
tags: Java
---
**Intent:** Define a one-to-many dependency between objects so that when one

View File

@ -3,8 +3,8 @@ layout: pattern
title: Poison Pill
folder: poison-pill
permalink: /patterns/poison-pill/
categories: pattern_cat
tags: pattern_tag
categories: Other
tags: Java
---
**Intent:** Poison Pill is known predefined data item that allows to provide

View File

@ -3,8 +3,8 @@ layout: pattern
title: Private Class Data
folder: private-class-data
permalink: /patterns/private-class-data/
categories: pattern_cat
tags: pattern_tag
categories: Other
tags: Java
---
**Intent:** Private Class Data design pattern seeks to reduce exposure of

View File

@ -3,8 +3,8 @@ layout: pattern
title: Property
folder: property
permalink: /patterns/property/
categories: creational
tags: pattern_tag
categories: Creational
tags: Java
---
**Intent:** Create hierarchy of objects and new objects using already existing

View File

@ -3,8 +3,8 @@ layout: pattern
title: Prototype
folder: prototype
permalink: /patterns/prototype/
categories: creational
tags: pattern_tag
categories: Creational
tags: Java
---
**Intent:** Specify the kinds of objects to create using a prototypical

View File

@ -3,8 +3,8 @@ layout: pattern
title: Proxy
folder: proxy
permalink: /patterns/proxy/
categories: structural
tags: pattern_tag
categories: Structural
tags: Java
---
**Intent:** Provide a surrogate or placeholder for another object to control

View File

@ -3,8 +3,8 @@ layout: pattern
title: Repository
folder: repository
permalink: /patterns/repository/
categories: architectural
tags: pattern_tag
categories: Architectural
tags: Java
---
**Intent:** Repository layer is added between the domain and data mapping

View File

@ -3,8 +3,8 @@ layout: pattern
title: Resource Acquisition Is Initialization
folder: resource-acquisition-is-initialization
permalink: /patterns/resource-acquisition-is-initialization/
categories: pattern_cat
tags: pattern_tag
categories: Other
tags: Java
---
**Intent:** Resource Acquisition Is Initialization pattern can be used to implement exception safe resource management.

View File

@ -3,8 +3,8 @@ layout: pattern
title: Servant
folder: servant
permalink: /patterns/servant/
categories: structural
tags: pattern_tag
categories: Structural
tags: Java
---
**Intent:** Servant is used for providing some behavior to a group of classes.

View File

@ -3,8 +3,8 @@ layout: pattern
title: Service Layer
folder: service-layer
permalink: /patterns/service-layer/
categories: architectural
tags: pattern_tag
categories: Architectural
tags: Java
---
**Intent:** Service Layer is an abstraction over domain logic. Typically

View File

@ -3,8 +3,8 @@ layout: pattern
title: Service Locator
folder: service-locator
permalink: /patterns/service-locator/
categories: structural
tags: pattern_tag
categories: Structural
tags: Java
---
**Intent:** Encapsulate the processes involved in obtaining a service with a

View File

@ -3,8 +3,8 @@ layout: pattern
title: Singleton
folder: singleton
permalink: /patterns/singleton/
categories: creational
tags: pattern_tag
categories: Creational
tags: Java
---
**Intent:** Ensure a class only has one instance, and provide a global point of

View File

@ -3,8 +3,8 @@ layout: pattern
title: Specification
folder: specification
permalink: /patterns/specification/
categories: behavioral
tags: pattern_tag
categories: Behavioral
tags: Java
---
**Intent:** Specification pattern separates the statement of how to match a

View File

@ -3,8 +3,8 @@ layout: pattern
title: State
folder: state
permalink: /patterns/state/
categories: behavioral
tags: pattern_tag
categories: Behavioral
tags: Java
---
**Intent:** Allow an object to alter its behavior when its internal state

View File

@ -3,8 +3,8 @@ layout: pattern
title: Step Builder
folder: step-builder
permalink: /patterns/step-builder/
categories: creational
tags: pattern_tag
categories: Creational
tags: Java
---
**Intent:** An extension of the Builder pattern that fully guides the user through the creation of the object with no chances of confusion.

View File

@ -3,8 +3,8 @@ layout: pattern
title: Strategy
folder: strategy
permalink: /patterns/strategy/
categories: behavioral
tags: pattern_tag
categories: Behavioral
tags: Java
---
**Intent:** Define a family of algorithms, encapsulate each one, and make them

View File

@ -3,8 +3,8 @@ layout: pattern
title: Template method
folder: template-method
permalink: /patterns/template-method/
categories: behavioral
tags: pattern_tag
categories: Behavioral
tags: Java
---
**Intent:** Define the skeleton of an algorithm in an operation, deferring some

View File

@ -3,8 +3,8 @@ layout: pattern
title: Thread Pool
folder: thread-pool
permalink: /patterns/thread-pool/
categories: concurrency
tags: pattern_tag
categories: Concurrency
tags: Java
---
**Intent:** It is often the case that tasks to be executed are short-lived and

View File

@ -3,8 +3,8 @@ layout: pattern
title: Tolerant Reader
folder: tolerant-reader
permalink: /patterns/tolerant-reader/
categories: integration
tags: pattern_tag
categories: Integration
tags: Java
---
**Intent:** Tolerant Reader is an integration pattern that helps creating

View File

@ -3,8 +3,8 @@ layout: pattern
title: Visitor
folder: visitor
permalink: /patterns/visitor/
categories: behavioral
tags: pattern_tag
categories: Behavioral
tags: Java
---
**Intent:** Represent an operation to be performed on the elements of an object