diff --git a/callback/src/main/java/com/iluwatar/callback/LambdasApp.java b/callback/src/main/java/com/iluwatar/callback/LambdasApp.java new file mode 100644 index 000000000..19dd17eae --- /dev/null +++ b/callback/src/main/java/com/iluwatar/callback/LambdasApp.java @@ -0,0 +1,19 @@ +package com.iluwatar.callback; + +/** + * + * This example generates the exact same output as {@link App} however the callback has been + * defined as a Lambdas expression. + * + */ +public class LambdasApp { + + /** + * Program entry point + */ + public static void main(String[] args) { + Task task = new SimpleTask(); + Callback c = () -> System.out.println("I'm done now."); + task.executeWith(c); + } +} diff --git a/callback/src/test/java/com/iluwatar/callback/AppTest.java b/callback/src/test/java/com/iluwatar/callback/AppTest.java index 67046a175..28d6eaa1c 100644 --- a/callback/src/test/java/com/iluwatar/callback/AppTest.java +++ b/callback/src/test/java/com/iluwatar/callback/AppTest.java @@ -36,4 +36,22 @@ public class AppTest { assertEquals("Callback called twice", new Integer(2), callingCount); } + + @Test + public void testWithLambdasExample() { + Callback callback = () -> callingCount++; + + Task task = new SimpleTask(); + + assertEquals("Initial calling count of 0", new Integer(0), callingCount); + + task.executeWith(callback); + + assertEquals("Callback called once", new Integer(1), callingCount); + + task.executeWith(callback); + + assertEquals("Callback called twice", new Integer(2), callingCount); + + } } diff --git a/event-driven-architecture/etc/class_diagram.png b/event-driven-architecture/etc/class_diagram.png deleted file mode 100644 index 69560e1f4..000000000 Binary files a/event-driven-architecture/etc/class_diagram.png and /dev/null differ diff --git a/event-driven-architecture/etc/eda.png b/event-driven-architecture/etc/eda.png new file mode 100644 index 000000000..38c433a40 Binary files /dev/null and b/event-driven-architecture/etc/eda.png differ diff --git a/event-driven-architecture/etc/eda.ucls b/event-driven-architecture/etc/eda.ucls new file mode 100644 index 000000000..4ddb8b20c --- /dev/null +++ b/event-driven-architecture/etc/eda.ucls @@ -0,0 +1,196 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/event-driven-architecture/index.md b/event-driven-architecture/index.md index 40d84004d..6c2ae99c6 100644 --- a/event-driven-architecture/index.md +++ b/event-driven-architecture/index.md @@ -6,7 +6,7 @@ permalink: /patterns/event-driven-architecture **Intent:** Send and notify state changes of your objects to other applications using an Event-driven Architecture. -![alt text](./etc/class_diagram.png "Event Driven Architecture") +![alt text](./etc/eda.png "Event Driven Architecture") **Applicability:** Use an Event-driven architecture when