From a34e7be9c2377e64c5a2759d053997ef2d340f70 Mon Sep 17 00:00:00 2001 From: Aleksandar Dudukovic Date: Fri, 28 Apr 2017 19:35:19 +0200 Subject: [PATCH 01/11] check commit --- marker/pom.xml | 15 +++++++++++++++ marker/src/main/java/App.java | 6 ++++++ pom.xml | 1 + 3 files changed, 22 insertions(+) create mode 100644 marker/pom.xml create mode 100644 marker/src/main/java/App.java diff --git a/marker/pom.xml b/marker/pom.xml new file mode 100644 index 000000000000..99dca27a3b96 --- /dev/null +++ b/marker/pom.xml @@ -0,0 +1,15 @@ + + + + java-design-patterns + com.iluwatar + 1.16.0-SNAPSHOT + + 4.0.0 + + marker + + + \ No newline at end of file diff --git a/marker/src/main/java/App.java b/marker/src/main/java/App.java new file mode 100644 index 000000000000..233db22c97ce --- /dev/null +++ b/marker/src/main/java/App.java @@ -0,0 +1,6 @@ +/** + * Created by Alexis on 28-Apr-17. + */ +public class App { + +} diff --git a/pom.xml b/pom.xml index a45f0e1f36fb..7ca284557763 100644 --- a/pom.xml +++ b/pom.xml @@ -139,6 +139,7 @@ converter guarded-suspension balking + marker From 8530d01e10b092d47a0b61559b2ca9eb10767011 Mon Sep 17 00:00:00 2001 From: Aleksandar Dudukovic Date: Sat, 29 Apr 2017 16:35:57 +0200 Subject: [PATCH 02/11] code implemented --- marker/src/main/java/App.java | 7 +++++++ marker/src/main/java/Guard.java | 10 ++++++++++ marker/src/main/java/Permission.java | 7 +++++++ 3 files changed, 24 insertions(+) create mode 100644 marker/src/main/java/Guard.java create mode 100644 marker/src/main/java/Permission.java diff --git a/marker/src/main/java/App.java b/marker/src/main/java/App.java index 233db22c97ce..ca8c036f77c3 100644 --- a/marker/src/main/java/App.java +++ b/marker/src/main/java/App.java @@ -2,5 +2,12 @@ * Created by Alexis on 28-Apr-17. */ public class App { + public static void main(String[] args) { + Guard guard = new Guard(); + if (guard instanceof Permission) { + guard.enter(); + } + } } + diff --git a/marker/src/main/java/Guard.java b/marker/src/main/java/Guard.java new file mode 100644 index 000000000000..93db6b4d7c04 --- /dev/null +++ b/marker/src/main/java/Guard.java @@ -0,0 +1,10 @@ +/** + * Created by Alexis on 29-Apr-17. + */ +public class Guard implements Permission { + + protected static void enter() { + System.out.println("You can enter"); + } + +} diff --git a/marker/src/main/java/Permission.java b/marker/src/main/java/Permission.java new file mode 100644 index 000000000000..a422e955cda2 --- /dev/null +++ b/marker/src/main/java/Permission.java @@ -0,0 +1,7 @@ +/** + * Created by Alexis on 29-Apr-17. + * Interface without any methods + * Marker interface is based on that assumption + */ +public interface Permission { +} From 20062faae69c8a3b9b2b7d15080e13cc5bda5667 Mon Sep 17 00:00:00 2001 From: Aleksandar Dudukovic Date: Wed, 3 May 2017 17:50:35 +0200 Subject: [PATCH 03/11] All without Readme and pumlid --- marker/etc/MarkerDiagram.png | Bin 0 -> 6461 bytes marker/etc/MarkerDiagram.ucls | 41 ++++++++++++++++++++++++++++ marker/pom.xml | 15 ++++++++++ marker/src/main/java/App.java | 31 +++++++++++++++++++++ marker/src/main/java/Thief.java | 12 ++++++++ marker/src/test/java/AppTest.java | 17 ++++++++++++ marker/src/test/java/GuardTest.java | 16 +++++++++++ marker/src/test/java/ThiefTest.java | 15 ++++++++++ 8 files changed, 147 insertions(+) create mode 100644 marker/etc/MarkerDiagram.png create mode 100644 marker/etc/MarkerDiagram.ucls create mode 100644 marker/src/main/java/Thief.java create mode 100644 marker/src/test/java/AppTest.java create mode 100644 marker/src/test/java/GuardTest.java create mode 100644 marker/src/test/java/ThiefTest.java diff --git a/marker/etc/MarkerDiagram.png b/marker/etc/MarkerDiagram.png new file mode 100644 index 0000000000000000000000000000000000000000..6ed4f9c567809787d9317733a2e4fe40cbe3284c GIT binary patch literal 6461 zcma)Bc{G&o-yRG?QbuI|W}7Hfwu~?cQ64hNlBE)|FO7BVl9VNTmWLsXt;k*s3E3Hj z7+FFxW6i$vPQUN>oZs(#&-M` z8-@@F4G;C=I6+H&g8A+OLLl5wof~RKJ{e1(YZTvXK%4QqJ$8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 100644 index 000000000000..0f8376e40e23 --- /dev/null +++ b/marker/etc/MarkerDiagram.ucls @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/marker/pom.xml b/marker/pom.xml index 99dca27a3b96..74969d2eb2c3 100644 --- a/marker/pom.xml +++ b/marker/pom.xml @@ -10,6 +10,21 @@ 4.0.0 marker + + + org.junit.jupiter + junit-jupiter-api + RELEASE + + + junit + junit + + + junit + junit + + \ No newline at end of file diff --git a/marker/src/main/java/App.java b/marker/src/main/java/App.java index ca8c036f77c3..10ec017dfd89 100644 --- a/marker/src/main/java/App.java +++ b/marker/src/main/java/App.java @@ -1,12 +1,43 @@ /** * Created by Alexis on 28-Apr-17. + * With Marker interface idea is to make empty interface and extend it. + * Basically it is just to identify the special objects from normal objects. + * Like in case of serialization , objects that need to be serialized must implement serializable interface + * (it is empty interface) and down the line writeObject() method must be checking + * if it is a instance of serializable or not. + *

+ * Marker interface vs annotation + * Marker interfaces and marker annotations both have their uses, + * neither of them is obsolete or always better then the other one. + * If you want to define a type that does not have any new methods associated with it, + * a marker interface is the way to go. + * If you want to mark program elements other than classes and interfaces, + * to allow for the possibility of adding more information to the marker in the future, + * or to fit the marker into a framework that already makes heavy use of annotation types, + * then a marker annotation is the correct choice */ public class App { + + /** + * Program entry point + * + * @param args command line args + */ public static void main(String[] args) { + Guard guard = new Guard(); + Thief thief = new Thief(); if (guard instanceof Permission) { guard.enter(); + } else { + System.out.println("You have no permission to enter, please leave this area"); + } + + if (thief instanceof Permission) { + thief.steal(); + } else { + thief.doNothing(); } } } diff --git a/marker/src/main/java/Thief.java b/marker/src/main/java/Thief.java new file mode 100644 index 000000000000..33eac5aca749 --- /dev/null +++ b/marker/src/main/java/Thief.java @@ -0,0 +1,12 @@ +/** + * Created by Alexis on 02-May-17. + */ +public class Thief { + protected static void steal() { + System.out.println("Steal valuable items"); + } + + protected static void doNothing() { + System.out.println("Pretend nothing happened and just leave"); + } +} diff --git a/marker/src/test/java/AppTest.java b/marker/src/test/java/AppTest.java new file mode 100644 index 000000000000..615a3c910387 --- /dev/null +++ b/marker/src/test/java/AppTest.java @@ -0,0 +1,17 @@ +/** + * Created by Alexis on 01-May-17. + */ + +import org.junit.Test; + +/** + * Application test + */ +public class AppTest { + + @Test + public void test() { + String[] args = {}; + App.main(args); + } +} diff --git a/marker/src/test/java/GuardTest.java b/marker/src/test/java/GuardTest.java new file mode 100644 index 000000000000..4594473676b0 --- /dev/null +++ b/marker/src/test/java/GuardTest.java @@ -0,0 +1,16 @@ +import org.junit.Test; + +import static org.hamcrest.CoreMatchers.instanceOf; +import static org.junit.Assert.assertThat; + +/** + * Created by Alexis on 02-May-17. + */ +public class GuardTest { + + @Test + public void testGuard() { + Guard guard = new Guard(); + assertThat(guard, instanceOf(Permission.class)); + } +} diff --git a/marker/src/test/java/ThiefTest.java b/marker/src/test/java/ThiefTest.java new file mode 100644 index 000000000000..37409ecb34fc --- /dev/null +++ b/marker/src/test/java/ThiefTest.java @@ -0,0 +1,15 @@ +/** + * Created by Alexis on 02-May-17. + */ + +import org.junit.Test; + +import static org.junit.Assert.assertFalse; + +public class ThiefTest { + @Test + public void testGuard() { + Thief thief = new Thief(); + assertFalse(thief instanceof Permission); + } +} From 6d87f63ed5e9705c328795f3ca8ebeabbe5210a0 Mon Sep 17 00:00:00 2001 From: 4lexis Date: Wed, 3 May 2017 19:48:29 +0200 Subject: [PATCH 04/11] Added README.md --- marker/README.md | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 marker/README.md diff --git a/marker/README.md b/marker/README.md new file mode 100644 index 000000000000..dbca4ca83e34 --- /dev/null +++ b/marker/README.md @@ -0,0 +1,30 @@ +--- +layout: pattern +title: Marker Interface +folder: marker +permalink: /patterns/marker/ +categories: Design +tags: + - Java + - Difficulty-Beginner +--- + +## Intent +Using empy interfaces as markers to distinguish special treated objects. + +![alt text](./marker/etc/MarkerDiagram.png "Marker Interface") + +## Applicability +Use the Marker Interface pattern when + +* you want to identify the special objects from normal objects +* define a type that is implemented by instances of the marked class, marker annotations can not do that + +## Real world examples + +* [javase.7.docs.api.java.io.Serializable](https://docs.oracle.com/javase/7/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) + +## Credits + +* [Effective Java 2nd Edition by Joshua Bloch](https://www.amazon.com/Effective-Java-2nd-Joshua-Bloch/dp/0321356683) From be3f4dce50253de29632c2ba98328e4230a57f82 Mon Sep 17 00:00:00 2001 From: 4lexis Date: Wed, 3 May 2017 19:49:25 +0200 Subject: [PATCH 05/11] Update Picture --- marker/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/marker/README.md b/marker/README.md index dbca4ca83e34..8ff25100ab0f 100644 --- a/marker/README.md +++ b/marker/README.md @@ -12,7 +12,7 @@ tags: ## Intent Using empy interfaces as markers to distinguish special treated objects. -![alt text](./marker/etc/MarkerDiagram.png "Marker Interface") +![alt text](./etc/MarkerDiagram.png "Marker Interface") ## Applicability Use the Marker Interface pattern when From 6e0b3e37ea10e26241cb4e5d56c2106de37a19cd Mon Sep 17 00:00:00 2001 From: Aleksandar Dudukovic Date: Wed, 3 May 2017 19:57:14 +0200 Subject: [PATCH 06/11] updated pom.xml --- marker/pom.xml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/marker/pom.xml b/marker/pom.xml index 74969d2eb2c3..c7345d8ee375 100644 --- a/marker/pom.xml +++ b/marker/pom.xml @@ -1,4 +1,24 @@ + + From 66c6f30c1c31a5dc09d6b7a14e1b7c96de4effd0 Mon Sep 17 00:00:00 2001 From: 4lexis Date: Wed, 3 May 2017 20:34:27 +0200 Subject: [PATCH 07/11] #567 Updated pom.xml --- marker/pom.xml | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/marker/pom.xml b/marker/pom.xml index 74969d2eb2c3..ceab669aa35f 100644 --- a/marker/pom.xml +++ b/marker/pom.xml @@ -1,4 +1,23 @@ + @@ -27,4 +46,4 @@ - \ No newline at end of file + From 34b09c75ec3e1c6369e2c837896259bc6885934d Mon Sep 17 00:00:00 2001 From: 4lexis Date: Wed, 3 May 2017 20:51:51 +0200 Subject: [PATCH 08/11] #567 added .gitignore --- marker/.gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 marker/.gitignore diff --git a/marker/.gitignore b/marker/.gitignore new file mode 100644 index 000000000000..b83d22266ac8 --- /dev/null +++ b/marker/.gitignore @@ -0,0 +1 @@ +/target/ From 6ecf994258d1f042121f910d639b887f8934a958 Mon Sep 17 00:00:00 2001 From: Aleksandar Dudukovic Date: Wed, 3 May 2017 21:42:15 +0200 Subject: [PATCH 09/11] #567 pom.xml align fix --- marker/pom.xml | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/marker/pom.xml b/marker/pom.xml index ceab669aa35f..ab92bdbc6ba3 100644 --- a/marker/pom.xml +++ b/marker/pom.xml @@ -21,29 +21,29 @@ - - java-design-patterns - com.iluwatar - 1.16.0-SNAPSHOT - - 4.0.0 + + java-design-patterns + com.iluwatar + 1.16.0-SNAPSHOT + + 4.0.0 - marker - - - org.junit.jupiter - junit-jupiter-api - RELEASE - - - junit - junit - - - junit - junit - - + marker + + + org.junit.jupiter + junit-jupiter-api + RELEASE + + + junit + junit + + + junit + junit + + From 1abd96a9c8f9a07bee0048b43d4b09f0391dc5f9 Mon Sep 17 00:00:00 2001 From: Aleksandar Dudukovic Date: Wed, 3 May 2017 22:09:47 +0200 Subject: [PATCH 10/11] #567 checkstyle fix --- marker/src/test/java/ThiefTest.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/marker/src/test/java/ThiefTest.java b/marker/src/test/java/ThiefTest.java index 37409ecb34fc..bcc862803004 100644 --- a/marker/src/test/java/ThiefTest.java +++ b/marker/src/test/java/ThiefTest.java @@ -1,11 +1,10 @@ -/** - * Created by Alexis on 02-May-17. - */ - import org.junit.Test; import static org.junit.Assert.assertFalse; +/** + * Created by Alexis on 02-May-17. + */ public class ThiefTest { @Test public void testGuard() { From f2e35ec03df777b56f4af5f16c657211f0cfae4d Mon Sep 17 00:00:00 2001 From: Aleksandar Dudukovic Date: Tue, 23 May 2017 01:38:02 +0200 Subject: [PATCH 11/11] #567 fix version and javadoc --- marker/README.md | 10 +++++----- marker/pom.xml | 10 +--------- marker/src/main/java/App.java | 6 +++++- marker/src/main/java/Guard.java | 11 ++++++++--- marker/src/main/java/Permission.java | 1 - marker/src/main/java/Thief.java | 12 +++++++++--- marker/src/test/java/AppTest.java | 4 ---- marker/src/test/java/GuardTest.java | 4 ++-- marker/src/test/java/ThiefTest.java | 6 +++--- 9 files changed, 33 insertions(+), 31 deletions(-) diff --git a/marker/README.md b/marker/README.md index 8ff25100ab0f..5bcdf96643db 100644 --- a/marker/README.md +++ b/marker/README.md @@ -10,20 +10,20 @@ tags: --- ## Intent -Using empy interfaces as markers to distinguish special treated objects. +Using empty interfaces as markers to distinguish special treated objects. ![alt text](./etc/MarkerDiagram.png "Marker Interface") ## Applicability Use the Marker Interface pattern when -* you want to identify the special objects from normal objects -* define a type that is implemented by instances of the marked class, marker annotations can not do that +* you want to identify the special objects from normal objects (to treat them differently) +* you want to mark that some object is available for certain sort of operations ## Real world examples -* [javase.7.docs.api.java.io.Serializable](https://docs.oracle.com/javase/7/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.io.Serializable](https://docs.oracle.com/javase/8/docs/api/java/io/Serializable.html) +* [javase.8.docs.api.java.lang.Cloneable](https://docs.oracle.com/javase/8/docs/api/java/lang/Cloneable.html) ## Credits diff --git a/marker/pom.xml b/marker/pom.xml index ab92bdbc6ba3..2842bd739e89 100644 --- a/marker/pom.xml +++ b/marker/pom.xml @@ -30,18 +30,10 @@ marker - - org.junit.jupiter - junit-jupiter-api - RELEASE - - - junit - junit - junit junit + test diff --git a/marker/src/main/java/App.java b/marker/src/main/java/App.java index 10ec017dfd89..7abdda8c451b 100644 --- a/marker/src/main/java/App.java +++ b/marker/src/main/java/App.java @@ -1,3 +1,6 @@ +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + /** * Created by Alexis on 28-Apr-17. * 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) { + final Logger logger = LoggerFactory.getLogger(App.class); Guard guard = new Guard(); Thief thief = new Thief(); if (guard instanceof Permission) { guard.enter(); } 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) { diff --git a/marker/src/main/java/Guard.java b/marker/src/main/java/Guard.java index 93db6b4d7c04..14016f0b146f 100644 --- a/marker/src/main/java/Guard.java +++ b/marker/src/main/java/Guard.java @@ -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 { + private static final Logger LOGGER = LoggerFactory.getLogger(Guard.class); + protected static void enter() { - System.out.println("You can enter"); - } + LOGGER.info("You can enter"); + } } diff --git a/marker/src/main/java/Permission.java b/marker/src/main/java/Permission.java index a422e955cda2..c6e78c49da2f 100644 --- a/marker/src/main/java/Permission.java +++ b/marker/src/main/java/Permission.java @@ -1,5 +1,4 @@ /** - * Created by Alexis on 29-Apr-17. * Interface without any methods * Marker interface is based on that assumption */ diff --git a/marker/src/main/java/Thief.java b/marker/src/main/java/Thief.java index 33eac5aca749..9105057e3133 100644 --- a/marker/src/main/java/Thief.java +++ b/marker/src/main/java/Thief.java @@ -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 { + + private static final Logger LOGGER = LoggerFactory.getLogger(Thief.class); + protected static void steal() { - System.out.println("Steal valuable items"); + LOGGER.info("Steal valuable items"); } protected static void doNothing() { - System.out.println("Pretend nothing happened and just leave"); + LOGGER.info("Pretend nothing happened and just leave"); } } diff --git a/marker/src/test/java/AppTest.java b/marker/src/test/java/AppTest.java index 615a3c910387..55fb2a17f75b 100644 --- a/marker/src/test/java/AppTest.java +++ b/marker/src/test/java/AppTest.java @@ -1,7 +1,3 @@ -/** - * Created by Alexis on 01-May-17. - */ - import org.junit.Test; /** diff --git a/marker/src/test/java/GuardTest.java b/marker/src/test/java/GuardTest.java index 4594473676b0..8b33b6e7f8d9 100644 --- a/marker/src/test/java/GuardTest.java +++ b/marker/src/test/java/GuardTest.java @@ -4,7 +4,7 @@ import static org.junit.Assert.assertThat; /** - * Created by Alexis on 02-May-17. + * Guard test */ public class GuardTest { @@ -13,4 +13,4 @@ public void testGuard() { Guard guard = new Guard(); assertThat(guard, instanceOf(Permission.class)); } -} +} \ No newline at end of file diff --git a/marker/src/test/java/ThiefTest.java b/marker/src/test/java/ThiefTest.java index bcc862803004..71fe82b68dfd 100644 --- a/marker/src/test/java/ThiefTest.java +++ b/marker/src/test/java/ThiefTest.java @@ -3,12 +3,12 @@ import static org.junit.Assert.assertFalse; /** - * Created by Alexis on 02-May-17. + * Thief test */ public class ThiefTest { @Test - public void testGuard() { + public void testThief() { Thief thief = new Thief(); assertFalse(thief instanceof Permission); } -} +} \ No newline at end of file