#567 fix version and javadoc
This commit is contained in:
parent
1abd96a9c8
commit
f2e35ec03d
@ -10,20 +10,20 @@ tags:
|
|||||||
---
|
---
|
||||||
|
|
||||||
## Intent
|
## Intent
|
||||||
Using empy interfaces as markers to distinguish special treated objects.
|
Using empty interfaces as markers to distinguish special treated objects.
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
## Applicability
|
## Applicability
|
||||||
Use the Marker Interface pattern when
|
Use the Marker Interface pattern when
|
||||||
|
|
||||||
* you want to identify the special objects from normal objects
|
* you want to identify the special objects from normal objects (to treat them differently)
|
||||||
* define a type that is implemented by instances of the marked class, marker annotations can not do that
|
* you want to mark that some object is available for certain sort of operations
|
||||||
|
|
||||||
## Real world examples
|
## Real world examples
|
||||||
|
|
||||||
* [javase.7.docs.api.java.io.Serializable](https://docs.oracle.com/javase/7/docs/api/java/io/Serializable.html)
|
* [javase.8.docs.api.java.io.Serializable](https://docs.oracle.com/javase/8/docs/api/java/io/Serializable.html)
|
||||||
* [javase.7.docs.api.java.lang.Cloneable](https://docs.oracle.com/javase/7/docs/api/java/lang/Cloneable.html)
|
* [javase.8.docs.api.java.lang.Cloneable](https://docs.oracle.com/javase/8/docs/api/java/lang/Cloneable.html)
|
||||||
|
|
||||||
## Credits
|
## Credits
|
||||||
|
|
||||||
|
@ -30,18 +30,10 @@
|
|||||||
|
|
||||||
<artifactId>marker</artifactId>
|
<artifactId>marker</artifactId>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
|
||||||
<groupId>org.junit.jupiter</groupId>
|
|
||||||
<artifactId>junit-jupiter-api</artifactId>
|
|
||||||
<version>RELEASE</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>junit</groupId>
|
|
||||||
<artifactId>junit</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>junit</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Alexis on 28-Apr-17.
|
* Created by Alexis on 28-Apr-17.
|
||||||
* With Marker interface idea is to make empty interface and extend it.
|
* With Marker interface idea is to make empty interface and extend it.
|
||||||
@ -25,13 +28,14 @@ public class App {
|
|||||||
*/
|
*/
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
final Logger logger = LoggerFactory.getLogger(App.class);
|
||||||
Guard guard = new Guard();
|
Guard guard = new Guard();
|
||||||
Thief thief = new Thief();
|
Thief thief = new Thief();
|
||||||
|
|
||||||
if (guard instanceof Permission) {
|
if (guard instanceof Permission) {
|
||||||
guard.enter();
|
guard.enter();
|
||||||
} else {
|
} else {
|
||||||
System.out.println("You have no permission to enter, please leave this area");
|
logger.info("You have no permission to enter, please leave this area");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (thief instanceof Permission) {
|
if (thief instanceof Permission) {
|
||||||
|
@ -1,10 +1,15 @@
|
|||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Alexis on 29-Apr-17.
|
* Class defining Guard
|
||||||
*/
|
*/
|
||||||
public class Guard implements Permission {
|
public class Guard implements Permission {
|
||||||
|
|
||||||
protected static void enter() {
|
private static final Logger LOGGER = LoggerFactory.getLogger(Guard.class);
|
||||||
System.out.println("You can enter");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
protected static void enter() {
|
||||||
|
|
||||||
|
LOGGER.info("You can enter");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
/**
|
/**
|
||||||
* Created by Alexis on 29-Apr-17.
|
|
||||||
* Interface without any methods
|
* Interface without any methods
|
||||||
* Marker interface is based on that assumption
|
* Marker interface is based on that assumption
|
||||||
*/
|
*/
|
||||||
|
@ -1,12 +1,18 @@
|
|||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Alexis on 02-May-17.
|
* Class defining Thief
|
||||||
*/
|
*/
|
||||||
public class Thief {
|
public class Thief {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(Thief.class);
|
||||||
|
|
||||||
protected static void steal() {
|
protected static void steal() {
|
||||||
System.out.println("Steal valuable items");
|
LOGGER.info("Steal valuable items");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static void doNothing() {
|
protected static void doNothing() {
|
||||||
System.out.println("Pretend nothing happened and just leave");
|
LOGGER.info("Pretend nothing happened and just leave");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,3 @@
|
|||||||
/**
|
|
||||||
* Created by Alexis on 01-May-17.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -4,7 +4,7 @@ import static org.hamcrest.CoreMatchers.instanceOf;
|
|||||||
import static org.junit.Assert.assertThat;
|
import static org.junit.Assert.assertThat;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Alexis on 02-May-17.
|
* Guard test
|
||||||
*/
|
*/
|
||||||
public class GuardTest {
|
public class GuardTest {
|
||||||
|
|
||||||
@ -13,4 +13,4 @@ public class GuardTest {
|
|||||||
Guard guard = new Guard();
|
Guard guard = new Guard();
|
||||||
assertThat(guard, instanceOf(Permission.class));
|
assertThat(guard, instanceOf(Permission.class));
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -3,12 +3,12 @@ import org.junit.Test;
|
|||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Alexis on 02-May-17.
|
* Thief test
|
||||||
*/
|
*/
|
||||||
public class ThiefTest {
|
public class ThiefTest {
|
||||||
@Test
|
@Test
|
||||||
public void testGuard() {
|
public void testThief() {
|
||||||
Thief thief = new Thief();
|
Thief thief = new Thief();
|
||||||
assertFalse(thief instanceof Permission);
|
assertFalse(thief instanceof Permission);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user