Changed package naming across all examples.

This commit is contained in:
Ilkka Seppala
2015-05-31 11:55:18 +03:00
parent 703ebd3e20
commit 8524c75ba6
437 changed files with 1095 additions and 1402 deletions

View File

@@ -0,0 +1,19 @@
package com.iluwatar.callback;
/**
* Callback pattern is more native for functional languages where function is treated as first-class citizen.
* Prior to Java8 can be simulated using simple (alike command) interfaces.
*/
public class App {
public static void main(String[] args) {
Task task = new SimpleTask();
Callback callback = new Callback() {
@Override
public void call() {
System.out.println("I'm done now.");
}
};
task.executeWith(callback);
}
}

View File

@@ -0,0 +1,9 @@
package com.iluwatar.callback;
/**
* Callback interface
*/
public interface Callback {
public void call();
}

View File

@@ -0,0 +1,13 @@
package com.iluwatar.callback;
/**
* Implementation of task that need to be executed
*/
public class SimpleTask extends Task {
@Override
public void execute() {
System.out.println("Perform some important activity.");
}
}

View File

@@ -0,0 +1,16 @@
package com.iluwatar.callback;
/**
* Template-method class for callback hook execution
*/
public abstract class Task {
public final void executeWith(Callback callback) {
execute();
if (callback != null) {
callback.call();
}
}
public abstract void execute();
}