diff --git a/callback/README.md b/callback/README.md index 78766cc15..34543f0bb 100644 --- a/callback/README.md +++ b/callback/README.md @@ -9,14 +9,16 @@ tags: --- ## Intent -Callback is a piece of executable code that is passed as an argument to other code, which is expected to call back -(execute) the argument at some convenient time. + +Callback is a piece of executable code that is passed as an argument to other code, which is +expected to call back (execute) the argument at some convenient time. ## Explanation Real world example -> We need to be notified after executing task has finished. We pass a callback method for the executor and wait for it to call back on us. +> We need to be notified after executing task has finished. We pass a callback method for +> the executor and wait for it to call back on us. In plain words @@ -24,7 +26,9 @@ In plain words Wikipedia says -> In computer programming, a callback, also known as a "call-after" function, is any executable code that is passed as an argument to other code; that other code is expected to call back (execute) the argument at a given time. +> In computer programming, a callback, also known as a "call-after" function, is any executable +> code that is passed as an argument to other code; that other code is expected to call +> back (execute) the argument at a given time. **Programmatic Example** @@ -61,7 +65,7 @@ public final class SimpleTask extends Task { } ``` -Finally here's how we execute a task and receive a callback when it's finished. +Finally, here's how we execute a task and receive a callback when it's finished. ```java var task = new SimpleTask(); @@ -69,13 +73,15 @@ Finally here's how we execute a task and receive a callback when it's finished. ``` ## Class diagram + ![alt text](./etc/callback.png "Callback") ## Applicability + Use the Callback pattern when * when some arbitrary synchronous or asynchronous action must be performed after execution of some defined activity. ## Real world examples -* [CyclicBarrier](http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/CyclicBarrier.html#CyclicBarrier%28int,%20java.lang.Runnable%29) constructor can accept callback that will be triggered every time when barrier is tripped. +* [CyclicBarrier](http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/CyclicBarrier.html#CyclicBarrier%28int,%20java.lang.Runnable%29) constructor can accept a callback that will be triggered every time a barrier is tripped. diff --git a/callback/etc/callback.png b/callback/etc/callback.png index a81745871..7b499f79f 100644 Binary files a/callback/etc/callback.png and b/callback/etc/callback.png differ diff --git a/callback/etc/callback.urm.puml b/callback/etc/callback.urm.puml index a666a4fdb..2d213eda8 100644 --- a/callback/etc/callback.urm.puml +++ b/callback/etc/callback.urm.puml @@ -8,11 +8,6 @@ package com.iluwatar.callback { interface Callback { + call() {abstract} } - class LambdasApp { - - LOGGER : Logger {static} - - LambdasApp() - + main(args : String[]) {static} - } class SimpleTask { - LOGGER : Logger {static} + SimpleTask()