Add README.md

This commit is contained in:
Sia Wai Suan 2018-02-20 09:48:44 +00:00
parent b73ef6e6c5
commit 565f5a4e70
4 changed files with 38 additions and 8 deletions

26
dirty-flag/README.md Normal file
View File

@ -0,0 +1,26 @@
---
layout: pattern
title: Dirty Flag
folder: dirty-flag
permalink: /patterns/dirty-flag/
categories: Other
tags:
- Java
- Difficulty-Easy
- Performance
---
## Intent
To avoid expensive re-acquisition of resources. The resources retain their identity, are kept in some
fast-access storage, and are re-used to avoid having to acquire them again.
![alt text](./etc/dirty-flag.png "Dirty Flag")
## Applicability
Use the Dirty Flag pattern when
* Repetitious acquisition, initialization, and release of the same resource causes unnecessary performance overhead.
## Credits
* [Design Patterns: Dirty Flag](https://www.takeupcode.com/podcast/89-design-patterns-dirty-flag/)

View File

@ -16,10 +16,14 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

View File

@ -24,7 +24,7 @@ package org.dirty.flag;
import java.io.IOException;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import com.iluwatar.dirtyflag.App;

View File

@ -22,13 +22,13 @@
*/
package org.dirty.flag;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.lang.reflect.Field;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import com.iluwatar.dirtyflag.DataFetcher;
@ -39,7 +39,7 @@ import com.iluwatar.dirtyflag.DataFetcher;
*/
public class DirtyFlagTest {
@Before
@BeforeEach
public void reset() throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException {
Field instance = DataFetcher.class.getDeclaredField("df");
instance.setAccessible(true);