Merge commit '8b020837eaacc9ed4497f3c2461984935314bfb8' into add-delegation-pattern
* commit '8b020837eaacc9ed4497f3c2461984935314bfb8': Checkstyle corrections Checkstyle configuration to look into test classes too Rephrase readme title Corrected difficulty for Visitor #213 Add performance tag to relevant patterns #213 Categorize and tag all patterns #213 Update CONTRIBUTING.MD Update CONTRIBUTING.MD add-contributing
This commit is contained in:
commit
52192de909
4
CONTRIBUTING.MD
Normal file
4
CONTRIBUTING.MD
Normal file
@ -0,0 +1,4 @@
|
||||
This is great you have something to contribute!
|
||||
|
||||
Before going any further please read the [wiki](https://github.com/iluwatar/java-design-patterns/wiki)
|
||||
with conventions and rules we used for this project.
|
@ -2,7 +2,7 @@
|
||||
that smart and dearly wants an empty line before a heading to be able to
|
||||
display it as such, e.g. website) -->
|
||||
|
||||
# Design pattern samples in Java
|
||||
# Design patterns implemented in Java
|
||||
|
||||
[](https://travis-ci.org/iluwatar/java-design-patterns)
|
||||
[](https://coveralls.io/r/iluwatar/java-design-patterns?branch=master)
|
||||
|
@ -7,6 +7,7 @@ categories: Creational
|
||||
tags:
|
||||
- Java
|
||||
- Gang Of Four
|
||||
- Difficulty-Intermediate
|
||||
---
|
||||
|
||||
**Also known as:** Kit
|
||||
|
@ -7,6 +7,7 @@ categories: Structural
|
||||
tags:
|
||||
- Java
|
||||
- Gang Of Four
|
||||
- Difficulty-Beginner
|
||||
---
|
||||
|
||||
**Also known as:** Wrapper
|
||||
|
@ -4,7 +4,10 @@ title: Async Method Invocation
|
||||
folder: async-method-invocation
|
||||
permalink: /patterns/async-method-invocation/
|
||||
categories: Concurrency
|
||||
tags: Java
|
||||
tags:
|
||||
- Java
|
||||
- Difficulty-Intermediate
|
||||
- Functional
|
||||
---
|
||||
|
||||
**Intent:** Asynchronous method invocation is pattern where the calling thread
|
||||
|
@ -89,9 +89,9 @@ public class ThreadAsyncExecutorTest {
|
||||
final Object result = new Object();
|
||||
final Callable<Object> task = mock(Callable.class);
|
||||
when(task.call()).thenAnswer(i -> {
|
||||
Thread.sleep(1500);
|
||||
return result;
|
||||
});
|
||||
Thread.sleep(1500);
|
||||
return result;
|
||||
});
|
||||
|
||||
final AsyncResult<Object> asyncResult = executor.startProcess(task);
|
||||
assertNotNull(asyncResult);
|
||||
@ -128,9 +128,9 @@ public class ThreadAsyncExecutorTest {
|
||||
final Object result = new Object();
|
||||
final Callable<Object> task = mock(Callable.class);
|
||||
when(task.call()).thenAnswer(i -> {
|
||||
Thread.sleep(1500);
|
||||
return result;
|
||||
});
|
||||
Thread.sleep(1500);
|
||||
return result;
|
||||
});
|
||||
|
||||
final AsyncCallback<Object> callback = mock(AsyncCallback.class);
|
||||
final AsyncResult<Object> asyncResult = executor.startProcess(task, callback);
|
||||
@ -177,9 +177,9 @@ public class ThreadAsyncExecutorTest {
|
||||
final Object result = new Object();
|
||||
final Callable<Object> task = mock(Callable.class);
|
||||
when(task.call()).thenAnswer(i -> {
|
||||
Thread.sleep(1500);
|
||||
return result;
|
||||
});
|
||||
Thread.sleep(1500);
|
||||
return result;
|
||||
});
|
||||
|
||||
final AsyncResult<Object> asyncResult = executor.startProcess(task);
|
||||
assertNotNull(asyncResult);
|
||||
|
@ -7,6 +7,7 @@ categories: Structural
|
||||
tags:
|
||||
- Java
|
||||
- Gang Of Four
|
||||
- Difficulty-Intermediate
|
||||
---
|
||||
|
||||
**Also known as:** Handle/Body
|
||||
|
@ -7,6 +7,7 @@ categories: Creational
|
||||
tags:
|
||||
- Java
|
||||
- Gang Of Four
|
||||
- Difficulty-Intermediate
|
||||
---
|
||||
|
||||
**Intent:** Separate the construction of a complex object from its
|
||||
|
@ -4,7 +4,9 @@ title: Business Delegate
|
||||
folder: business-delegate
|
||||
permalink: /patterns/business-delegate/
|
||||
categories: Business Tier
|
||||
tags: Java
|
||||
tags:
|
||||
- Java
|
||||
- Difficulty-Intermediate
|
||||
---
|
||||
|
||||
**Intent:** The Business Delegate pattern adds an abstraction layer between
|
||||
|
@ -6,6 +6,8 @@ permalink: /patterns/caching/
|
||||
categories: Other
|
||||
tags:
|
||||
- Java
|
||||
- Difficulty-Intermediate
|
||||
- Performance
|
||||
---
|
||||
|
||||
**Intent:** To avoid expensive re-acquisition of resources by not releasing
|
||||
|
@ -4,7 +4,11 @@ title: Callback
|
||||
folder: callback
|
||||
permalink: /patterns/callback/
|
||||
categories: Other
|
||||
tags: Java
|
||||
tags:
|
||||
- Java
|
||||
- Difficulty-Beginner
|
||||
- Functional
|
||||
- Idiom
|
||||
---
|
||||
|
||||
**Intent:** Callback is a piece of executable code that is passed as an
|
||||
|
@ -7,6 +7,7 @@ categories: Behavioral
|
||||
tags:
|
||||
- Java
|
||||
- Gang Of Four
|
||||
- Difficulty-Intermediate
|
||||
---
|
||||
|
||||
**Intent:** Avoid coupling the sender of a request to its receiver by giving
|
||||
|
9
checkstyle-suppressions.xml
Normal file
9
checkstyle-suppressions.xml
Normal file
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE suppressions PUBLIC "-//Puppy Crawl//DTD Suppressions 1.1//EN"
|
||||
"http://www.puppycrawl.com/dtds/suppressions_1_1.dtd">
|
||||
<suppressions>
|
||||
<suppress checks="AvoidStarImport" files="[\\/]src[\\/]test[\\/]java[\\/]"/>
|
||||
<suppress checks="[a-zA-Z0-9]*" files="[\\/]src[\\/]test[\\/]resources[\\/]"/>
|
||||
<suppress checks="[a-zA-Z0-9]*" files="[\\/]build[\\/]generated-sources[\\/]"/>
|
||||
<suppress checks="[a-zA-Z0-9]*" files="[\\/]src[\\/]main[\\/]resources[\\/]"/>
|
||||
</suppressions>
|
@ -158,7 +158,7 @@
|
||||
<property name="allowMissingThrowsTags" value="true"/>
|
||||
<property name="allowMissingReturnTag" value="true"/>
|
||||
<property name="minLineCount" value="2"/>
|
||||
<property name="allowedAnnotations" value="Override, Test, Before, After, Parameters, Given, When, BeforeClass, AfterClass"/>
|
||||
<property name="allowedAnnotations" value="Override, Test, Before, After, Parameters, Given, When, BeforeClass, AfterClass, Parameterized"/>
|
||||
<property name="allowThrowsTagsForSubclasses" value="true"/>
|
||||
</module>
|
||||
<module name="MethodName">
|
||||
@ -168,4 +168,9 @@
|
||||
</module>
|
||||
<module name="SingleLineJavadoc"/>
|
||||
</module>
|
||||
|
||||
<module name="SuppressionFilter">
|
||||
<property name="file" value="${config_loc}/checkstyle-suppressions.xml" default="checkstyle-suppressions.xml"/>
|
||||
</module>
|
||||
|
||||
</module>
|
||||
|
@ -7,6 +7,7 @@ categories: Behavioral
|
||||
tags:
|
||||
- Java
|
||||
- Gang Of Four
|
||||
- Difficulty-Intermediate
|
||||
---
|
||||
|
||||
**Also known as:** Action, Transaction
|
||||
|
@ -7,6 +7,7 @@ categories: Structural
|
||||
tags:
|
||||
- Java
|
||||
- Gang Of Four
|
||||
- Difficulty-Intermediate
|
||||
---
|
||||
|
||||
**Intent:** Compose objects into tree structures to represent part-whole
|
||||
|
@ -3,7 +3,7 @@ layout: pattern
|
||||
title: Data Access Object
|
||||
folder: dao
|
||||
permalink: /patterns/dao/
|
||||
categories: Architectural
|
||||
categories: Persistence Tier
|
||||
tags:
|
||||
- Java
|
||||
- Difficulty-Beginner
|
||||
|
@ -7,6 +7,7 @@ categories: Structural
|
||||
tags:
|
||||
- Java
|
||||
- Gang Of Four
|
||||
- Difficulty-Beginner
|
||||
---
|
||||
|
||||
**Also known as:** Wrapper
|
||||
|
@ -4,7 +4,9 @@ title: Dependency Injection
|
||||
folder: dependency-injection
|
||||
permalink: /patterns/dependency-injection/
|
||||
categories: Behavioral
|
||||
tags: Java
|
||||
tags:
|
||||
- Java
|
||||
- Difficulty-Beginner
|
||||
---
|
||||
|
||||
**Intent:** Dependency Injection is a software design pattern in which one or
|
||||
|
@ -4,7 +4,10 @@ title: Double Checked Locking
|
||||
folder: double-checked-locking
|
||||
permalink: /patterns/double-checked-locking/
|
||||
categories: Concurrency
|
||||
tags: Java
|
||||
tags:
|
||||
- Java
|
||||
- Difficulty-Beginner
|
||||
- Idiom
|
||||
---
|
||||
|
||||
**Intent:** Reduce the overhead of acquiring a lock by first testing the
|
||||
|
@ -14,7 +14,10 @@ import java.util.concurrent.TimeUnit;
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
import static junit.framework.TestCase.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
|
||||
/**
|
||||
* Date: 12/10/15 - 9:34 PM
|
||||
@ -74,8 +77,8 @@ public class InventoryTest {
|
||||
final ExecutorService executorService = Executors.newFixedThreadPool(THREAD_COUNT);
|
||||
for (int i = 0; i < THREAD_COUNT; i++) {
|
||||
executorService.execute(() -> {
|
||||
while (inventory.addItem(new Item())) {};
|
||||
});
|
||||
while (inventory.addItem(new Item())) {};
|
||||
});
|
||||
}
|
||||
|
||||
// Wait until all threads have finished
|
||||
|
@ -4,7 +4,10 @@ title: Double Dispatch
|
||||
folder: double-dispatch
|
||||
permalink: /patterns/double-dispatch/
|
||||
categories: Other
|
||||
tags: Java
|
||||
tags:
|
||||
- Java
|
||||
- Difficulty-Intermediate
|
||||
- Idiom
|
||||
---
|
||||
|
||||
**Intent:** Double Dispatch pattern is a way to create maintainable dynamic
|
||||
|
@ -7,7 +7,10 @@ import java.io.PrintStream;
|
||||
import java.util.Objects;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
|
||||
/**
|
||||
* Date: 12/10/15 - 8:37 PM
|
||||
|
@ -4,7 +4,9 @@ title: Event Aggregator
|
||||
folder: event-aggregator
|
||||
permalink: /patterns/event-aggregator/
|
||||
categories: Structural
|
||||
tags: Java
|
||||
tags:
|
||||
- Java
|
||||
- Difficulty-Beginner
|
||||
---
|
||||
|
||||
**Intent:** A system with lots of objects can lead to complexities when a
|
||||
|
@ -7,7 +7,11 @@ import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyZeroInteractions;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
|
||||
/**
|
||||
* Date: 12/12/15 - 10:58 PM
|
||||
|
@ -6,7 +6,11 @@ import org.junit.Test;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyZeroInteractions;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
|
||||
/**
|
||||
* Date: 12/12/15 - 3:04 PM
|
||||
|
@ -3,7 +3,11 @@ package com.iluwatar.event.aggregator;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyZeroInteractions;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
|
||||
/**
|
||||
* Date: 12/12/15 - 10:57 AM
|
||||
|
@ -4,7 +4,10 @@ title: Execute Around
|
||||
folder: execute-around
|
||||
permalink: /patterns/execute-around/
|
||||
categories: Other
|
||||
tags: Java
|
||||
tags:
|
||||
- Java
|
||||
- Difficulty-Beginner
|
||||
- Idiom
|
||||
---
|
||||
|
||||
**Intent:** Execute Around idiom frees the user from certain actions that
|
||||
|
@ -67,8 +67,8 @@ public class SimpleFileWriterTest {
|
||||
public void testIoException() throws Exception {
|
||||
final File temporaryFile = this.testFolder.newFile();
|
||||
new SimpleFileWriter(temporaryFile.getPath(), writer -> {
|
||||
throw new IOException("");
|
||||
});
|
||||
throw new IOException("");
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ categories: Structural
|
||||
tags:
|
||||
- Java
|
||||
- Gang Of Four
|
||||
- Difficulty-Beginner
|
||||
---
|
||||
|
||||
**Intent:** Provide a unified interface to a set of interfaces in a subsystem.
|
||||
|
@ -7,7 +7,9 @@ import org.junit.Test;
|
||||
import java.io.PrintStream;
|
||||
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
import static org.mockito.internal.verification.VerificationModeFactory.times;
|
||||
|
||||
/**
|
||||
|
@ -7,6 +7,7 @@ categories: Other
|
||||
tags:
|
||||
- Java
|
||||
- Difficulty-Intermediate
|
||||
- Functional
|
||||
---
|
||||
|
||||
**Intent:** A fluent interface provides an easy-readable, flowing interface, that often mimics a domain specific language. Using this pattern results in code that can be read nearly as human language.
|
||||
|
@ -4,7 +4,9 @@ title: Flux
|
||||
folder: flux
|
||||
permalink: /patterns/flux/
|
||||
categories: Presentation Tier
|
||||
tags: Java
|
||||
tags:
|
||||
- Java
|
||||
- Difficulty-Intermediate
|
||||
---
|
||||
|
||||
**Intent:** Flux eschews MVC in favor of a unidirectional data flow. When a
|
||||
|
@ -1,6 +1,11 @@
|
||||
package com.iluwatar.flux.dispatcher;
|
||||
|
||||
import com.iluwatar.flux.action.*;
|
||||
import com.iluwatar.flux.action.Action;
|
||||
import com.iluwatar.flux.action.ActionType;
|
||||
import com.iluwatar.flux.action.Content;
|
||||
import com.iluwatar.flux.action.ContentAction;
|
||||
import com.iluwatar.flux.action.MenuAction;
|
||||
import com.iluwatar.flux.action.MenuItem;
|
||||
import com.iluwatar.flux.store.Store;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@ -11,8 +16,13 @@ import java.lang.reflect.Field;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
|
||||
/**
|
||||
* Date: 12/12/15 - 8:22 PM
|
||||
|
@ -9,7 +9,11 @@ import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyZeroInteractions;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
|
||||
/**
|
||||
* Date: 12/12/15 - 10:18 PM
|
||||
|
@ -9,7 +9,11 @@ import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyZeroInteractions;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
|
||||
/**
|
||||
* Date: 12/12/15 - 10:18 PM
|
||||
|
@ -4,7 +4,11 @@ import com.iluwatar.flux.action.Content;
|
||||
import com.iluwatar.flux.store.ContentStore;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
|
||||
/**
|
||||
* Date: 12/12/15 - 10:31 PM
|
||||
|
@ -8,7 +8,11 @@ import com.iluwatar.flux.store.Store;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* Date: 12/12/15 - 10:31 PM
|
||||
|
@ -7,6 +7,8 @@ categories: Structural
|
||||
tags:
|
||||
- Java
|
||||
- Gang Of Four
|
||||
- Difficulty-Intermediate
|
||||
- Performance
|
||||
---
|
||||
|
||||
**Intent:** Use sharing to support large numbers of fine-grained objects
|
||||
|
@ -4,7 +4,9 @@ title: Front Controller
|
||||
folder: front-controller
|
||||
permalink: /patterns/front-controller/
|
||||
categories: Presentation Tier
|
||||
tags: Java
|
||||
tags:
|
||||
- Java
|
||||
- Difficulty-Intermediate
|
||||
---
|
||||
|
||||
**Intent:** Introduce a common handler for all requests for a web site. This
|
||||
|
@ -4,7 +4,9 @@ title: Half-Sync/Half-Async
|
||||
folder: half-sync-half-async
|
||||
permalink: /patterns/half-sync-half-async/
|
||||
categories: Concurrency
|
||||
tags: Java
|
||||
tags:
|
||||
- Java
|
||||
- Difficulty-Intermediate
|
||||
---
|
||||
|
||||
**Intent:** The Half-Sync/Half-Async pattern decouples synchronous I/O from
|
||||
|
@ -4,7 +4,9 @@ title: Intercepting Filter
|
||||
folder: intercepting-filter
|
||||
permalink: /patterns/intercepting-filter/
|
||||
categories: Behavioral
|
||||
tags: Java
|
||||
tags:
|
||||
- Java
|
||||
- Difficulty-Intermediate
|
||||
---
|
||||
|
||||
**Intent:** Provide pluggable filters to conduct necessary pre-processing and
|
||||
|
@ -4,7 +4,11 @@ import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyZeroInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* Date: 12/13/15 - 3:01 PM
|
||||
|
@ -7,6 +7,7 @@ categories: Behavioral
|
||||
tags:
|
||||
- Java
|
||||
- Gang Of Four
|
||||
- Difficulty-Intermediate
|
||||
---
|
||||
|
||||
**Intent:** Given a language, define a representation for its grammar along
|
||||
|
@ -4,7 +4,10 @@ title: Layers
|
||||
folder: layers
|
||||
permalink: /patterns/layers/
|
||||
categories: Architectural
|
||||
tags: Java
|
||||
tags:
|
||||
- Java
|
||||
- Difficulty-Intermediate
|
||||
- Spring
|
||||
---
|
||||
|
||||
**Intent:** Layers is an architectural style where software responsibilities are
|
||||
|
@ -88,8 +88,8 @@ public class CakeTest {
|
||||
cake.setTopping(topping);
|
||||
cake.addLayer(layer);
|
||||
|
||||
final String expected = "id=1234 topping=id=2345 name=topping calories=20 " +
|
||||
"layers=[id=3456 name=layer calories=100]";
|
||||
final String expected = "id=1234 topping=id=2345 name=topping calories=20 "
|
||||
+ "layers=[id=3456 name=layer calories=100]";
|
||||
assertEquals(expected, cake.toString());
|
||||
|
||||
}
|
||||
|
@ -4,7 +4,11 @@ title: Lazy Loading
|
||||
folder: lazy-loading
|
||||
permalink: /patterns/lazy-loading/
|
||||
categories: Other
|
||||
tags: Java
|
||||
tags:
|
||||
- Java
|
||||
- Difficulty-Beginner
|
||||
- Idiom
|
||||
- Performance
|
||||
---
|
||||
|
||||
**Intent:** Lazy loading is a design pattern commonly used to defer
|
||||
|
@ -12,7 +12,10 @@ import java.util.Collection;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
import static org.mockito.Mockito.verifyZeroInteractions;
|
||||
|
||||
/**
|
||||
* Date: 12/19/15 - 10:13 PM
|
||||
|
@ -7,6 +7,7 @@ categories: Behavioral
|
||||
tags:
|
||||
- Java
|
||||
- Gang Of Four
|
||||
- Difficulty-Intermediate
|
||||
---
|
||||
|
||||
**Also known as:** Token
|
||||
|
@ -7,6 +7,7 @@ categories: Integration
|
||||
tags:
|
||||
- Java
|
||||
- EIP
|
||||
- Camel
|
||||
---
|
||||
|
||||
**Intent:** When two applications communicate using a messaging system they do it by using logical addresses
|
||||
|
@ -4,7 +4,9 @@ title: Model-View-Controller
|
||||
folder: model-view-controller
|
||||
permalink: /patterns/model-view-controller/
|
||||
categories: Presentation Tier
|
||||
tags: Java
|
||||
tags:
|
||||
- Java
|
||||
- Difficulty-Intermediate
|
||||
---
|
||||
|
||||
**Intent:** Separate the user interface into three interconnected components:
|
||||
|
@ -4,7 +4,9 @@ title: Model-View-Presenter
|
||||
folder: model-view-presenter
|
||||
permalink: /patterns/model-view-presenter/
|
||||
categories: Presentation Tier
|
||||
tags: Java
|
||||
tags:
|
||||
- Java
|
||||
- Difficulty-Intermediate
|
||||
---
|
||||
|
||||
**Intent:** Apply a "Separation of Concerns" principle in a way that allows
|
||||
|
@ -4,7 +4,9 @@ title: MonoState
|
||||
folder: monostate
|
||||
permalink: /patterns/monostate/
|
||||
categories: Creational
|
||||
tags: Java
|
||||
tags:
|
||||
- Java
|
||||
- Difficulty-Beginner
|
||||
---
|
||||
|
||||
**Intent:** Enforces a behaviour like sharing the same state amongst all instances.
|
||||
|
@ -4,7 +4,9 @@ title: Multiton
|
||||
folder: multiton
|
||||
permalink: /patterns/multiton/
|
||||
categories: Creational
|
||||
tags: Java
|
||||
tags:
|
||||
- Java
|
||||
- Difficulty-Beginner
|
||||
---
|
||||
|
||||
**Intent:** Ensure a class only has limited number of instances, and provide a
|
||||
|
@ -4,7 +4,9 @@ title: Naked Objects
|
||||
folder: naked-objects
|
||||
permalink: /patterns/naked-objects/
|
||||
categories: Architectural
|
||||
tags: Java
|
||||
tags:
|
||||
- Java
|
||||
- Difficulty-Expert
|
||||
---
|
||||
|
||||
**Intent:** The Naked Objects architectural pattern is well suited for rapid
|
||||
|
@ -4,7 +4,9 @@ title: Null Object
|
||||
folder: null-object
|
||||
permalink: /patterns/null-object/
|
||||
categories: Behavioral
|
||||
tags: Java
|
||||
tags:
|
||||
- Java
|
||||
- Difficulty-Beginner
|
||||
---
|
||||
|
||||
**Intent:** In most object-oriented languages, such as Java or C#, references
|
||||
|
@ -4,7 +4,10 @@ title: Object Pool
|
||||
folder: object-pool
|
||||
permalink: /patterns/object-pool/
|
||||
categories: Creational
|
||||
tags: Java
|
||||
tags:
|
||||
- Java
|
||||
- Difficulty-Beginner
|
||||
- Performance
|
||||
---
|
||||
|
||||
**Intent:** When objects are expensive to create and they are needed only for
|
||||
|
@ -4,7 +4,9 @@ title: Poison Pill
|
||||
folder: poison-pill
|
||||
permalink: /patterns/poison-pill/
|
||||
categories: Other
|
||||
tags: Java
|
||||
tags:
|
||||
- Java
|
||||
- Difficulty-Intermediate
|
||||
---
|
||||
|
||||
**Intent:** Poison Pill is known predefined data item that allows to provide
|
||||
|
1
pom.xml
1
pom.xml
@ -258,6 +258,7 @@
|
||||
<encoding>UTF-8</encoding>
|
||||
<consoleOutput>true</consoleOutput>
|
||||
<failsOnError>true</failsOnError>
|
||||
<includeTestSourceDirectory>true</includeTestSourceDirectory>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
|
@ -4,7 +4,10 @@ title: Private Class Data
|
||||
folder: private-class-data
|
||||
permalink: /patterns/private-class-data/
|
||||
categories: Other
|
||||
tags: Java
|
||||
tags:
|
||||
- Java
|
||||
- Difficulty-Beginner
|
||||
- Idiom
|
||||
---
|
||||
|
||||
**Intent:** Private Class Data design pattern seeks to reduce exposure of
|
||||
|
@ -3,15 +3,16 @@ layout: pattern
|
||||
title: Producer Consumer
|
||||
folder: producer-consumer
|
||||
permalink: /patterns/producer-consumer/
|
||||
categories: Other
|
||||
tags: Java
|
||||
categories: Concurrency
|
||||
tags:
|
||||
- Java
|
||||
- Difficulty-Intermediate
|
||||
- I/O
|
||||
---
|
||||
|
||||
**Intent:** Producer Consumer Design pattern is a classic concurrency or threading pattern which reduces
|
||||
**Intent:** Producer Consumer Design pattern is a classic concurrency pattern which reduces
|
||||
coupling between Producer and Consumer by separating Identification of work with Execution of
|
||||
Work..
|
||||
|
||||
|
||||
Work.
|
||||
|
||||

|
||||
|
||||
@ -19,4 +20,3 @@ tags: Java
|
||||
|
||||
* decouple system by separate work in two process produce and consume.
|
||||
* addresses the issue of different timing require to produce work or consuming work
|
||||
|
||||
|
@ -4,7 +4,9 @@ title: Property
|
||||
folder: property
|
||||
permalink: /patterns/property/
|
||||
categories: Creational
|
||||
tags: Java
|
||||
tags:
|
||||
- Java
|
||||
- Difficulty-Beginner
|
||||
---
|
||||
|
||||
**Intent:** Create hierarchy of objects and new objects using already existing
|
||||
|
@ -7,6 +7,7 @@ categories: Creational
|
||||
tags:
|
||||
- Java
|
||||
- Gang Of Four
|
||||
- Difficulty-Beginner
|
||||
---
|
||||
|
||||
**Intent:** Specify the kinds of objects to create using a prototypical
|
||||
|
@ -7,7 +7,7 @@ categories: Structural
|
||||
tags:
|
||||
- Java
|
||||
- Gang Of Four
|
||||
- Difficulty-Intermediate
|
||||
- Difficulty-Beginner
|
||||
---
|
||||
|
||||
**Also known as:** Surrogate
|
||||
|
@ -7,6 +7,7 @@ categories: Integration
|
||||
tags:
|
||||
- Java
|
||||
- EIP
|
||||
- Camel
|
||||
---
|
||||
|
||||
**Intent:** Broadcast messages from sender to all the interested receivers.
|
||||
|
@ -3,10 +3,11 @@ layout: pattern
|
||||
title: Reactor
|
||||
folder: reactor
|
||||
permalink: /patterns/reactor/
|
||||
categories: Architectural
|
||||
categories: Concurrency
|
||||
tags:
|
||||
- Java
|
||||
- Difficulty-Expert
|
||||
- I/O
|
||||
---
|
||||
|
||||
**Intent:** The Reactor design pattern handles service requests that are delivered concurrently to an application by one or more clients. The application can register specific handlers for processing which are called by reactor on specific events. Dispatching of event handlers is performed by an initiation dispatcher, which manages the registered event handlers. Demultiplexing of service requests is performed by a synchronous event demultiplexer.
|
||||
|
@ -3,8 +3,11 @@ layout: pattern
|
||||
title: Repository
|
||||
folder: repository
|
||||
permalink: /patterns/repository/
|
||||
categories: Architectural
|
||||
tags: Java
|
||||
categories: Persistence Tier
|
||||
tags:
|
||||
- Java
|
||||
- Difficulty-Intermediate
|
||||
- Spring
|
||||
---
|
||||
|
||||
**Intent:** Repository layer is added between the domain and data mapping
|
||||
|
@ -90,8 +90,8 @@ public class AnnotationBasedRepositoryTest {
|
||||
|
||||
assertEquals(3, persons.size());
|
||||
assertTrue(persons.stream().allMatch((item) -> {
|
||||
return item.getAge() > 20 && item.getAge() < 40;
|
||||
}));
|
||||
return item.getAge() > 20 && item.getAge() < 40;
|
||||
}));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -88,8 +88,8 @@ public class RepositoryTest {
|
||||
|
||||
assertEquals(3, persons.size());
|
||||
assertTrue(persons.stream().allMatch((item) -> {
|
||||
return item.getAge() > 20 && item.getAge() < 40;
|
||||
}));
|
||||
return item.getAge() > 20 && item.getAge() < 40;
|
||||
}));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -4,7 +4,10 @@ title: Resource Acquisition Is Initialization
|
||||
folder: resource-acquisition-is-initialization
|
||||
permalink: /patterns/resource-acquisition-is-initialization/
|
||||
categories: Other
|
||||
tags: Java
|
||||
tags:
|
||||
- Java
|
||||
- Difficulty-Beginner
|
||||
- Idiom
|
||||
---
|
||||
|
||||
**Intent:** Resource Acquisition Is Initialization pattern can be used to implement exception safe resource management.
|
||||
|
@ -4,7 +4,9 @@ title: Servant
|
||||
folder: servant
|
||||
permalink: /patterns/servant/
|
||||
categories: Structural
|
||||
tags: Java
|
||||
tags:
|
||||
- Java
|
||||
- Difficulty-Beginner
|
||||
---
|
||||
|
||||
**Intent:** Servant is used for providing some behavior to a group of classes.
|
||||
|
@ -4,7 +4,9 @@ title: Service Layer
|
||||
folder: service-layer
|
||||
permalink: /patterns/service-layer/
|
||||
categories: Architectural
|
||||
tags: Java
|
||||
tags:
|
||||
- Java
|
||||
- Difficulty-Intermediate
|
||||
---
|
||||
|
||||
**Intent:** Service Layer is an abstraction over domain logic. Typically
|
||||
|
@ -4,7 +4,10 @@ title: Service Locator
|
||||
folder: service-locator
|
||||
permalink: /patterns/service-locator/
|
||||
categories: Structural
|
||||
tags: Java
|
||||
tags:
|
||||
- Java
|
||||
- Difficulty-Beginner
|
||||
- Performance
|
||||
---
|
||||
|
||||
**Intent:** Encapsulate the processes involved in obtaining a service with a
|
||||
|
@ -4,7 +4,9 @@ title: Specification
|
||||
folder: specification
|
||||
permalink: /patterns/specification/
|
||||
categories: Behavioral
|
||||
tags: Java
|
||||
tags:
|
||||
- Java
|
||||
- Difficulty-Beginner
|
||||
---
|
||||
|
||||
**Intent:** Specification pattern separates the statement of how to match a
|
||||
|
@ -4,7 +4,9 @@ title: Step Builder
|
||||
folder: step-builder
|
||||
permalink: /patterns/step-builder/
|
||||
categories: Creational
|
||||
tags: Java
|
||||
tags:
|
||||
- Java
|
||||
- Difficulty-Intermediate
|
||||
---
|
||||
|
||||
**Intent:** An extension of the Builder pattern that fully guides the user through the creation of the object with no chances of confusion.
|
||||
|
@ -4,7 +4,10 @@ title: Thread Pool
|
||||
folder: thread-pool
|
||||
permalink: /patterns/thread-pool/
|
||||
categories: Concurrency
|
||||
tags: Java
|
||||
tags:
|
||||
- Java
|
||||
- Difficulty-Intermediate
|
||||
- Performance
|
||||
---
|
||||
|
||||
**Intent:** It is often the case that tasks to be executed are short-lived and
|
||||
|
@ -4,7 +4,9 @@ title: Tolerant Reader
|
||||
folder: tolerant-reader
|
||||
permalink: /patterns/tolerant-reader/
|
||||
categories: Integration
|
||||
tags: Java
|
||||
tags:
|
||||
- Java
|
||||
- Difficulty-Beginner
|
||||
---
|
||||
|
||||
**Intent:** Tolerant Reader is an integration pattern that helps creating
|
||||
|
@ -4,14 +4,14 @@ title: Twin
|
||||
folder: twin
|
||||
permalink: /patterns/twin/
|
||||
categories: Creational
|
||||
tags: Java
|
||||
tags:
|
||||
- Java
|
||||
- Difficulty-Intermediate
|
||||
---
|
||||
|
||||
**Intent:** Twin pattern is a design pattern which provides a standard solution to simulate multiple
|
||||
inheritance in java
|
||||
|
||||
|
||||
|
||||

|
||||
|
||||
**Applicability:** Use the Twin idiom when
|
||||
@ -21,4 +21,4 @@ inheritance in java
|
||||
|
||||
**Credits:**
|
||||
|
||||
* [Twin – A Design Pattern for Modeling Multiple Inheritance](http://www.ssw.uni-linz.ac.at/Research/Papers/Moe99/Paper.pdf)
|
||||
* [Twin – A Design Pattern for Modeling Multiple Inheritance](http://www.ssw.uni-linz.ac.at/Research/Papers/Moe99/Paper.pdf)
|
||||
|
@ -6,7 +6,7 @@ permalink: /patterns/visitor/
|
||||
categories: Behavioral
|
||||
tags:
|
||||
- Java
|
||||
- Difficulty-Expert
|
||||
- Difficulty-Intermediate
|
||||
- Gang Of Four
|
||||
---
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user