* Adding support for maven assembly plugin to generate executable jar with all dependencies in built * Merge branch 'master' into issue-989 # Conflicts: # abstract-document/pom.xml # pom.xml * Adding maven assemly plugin for projects with name A * Update in format as per checkstyle, i.e. Spcae in place of tab with size of 2 * batch set - 2 having all project with B and C * issue-989 d-e-f * fixing eip pom and adding g-h-i-l-m-n Skipping naked object as it seems it doesn't have main method, will consider this at end * Adding for O and P projects Skipping Object-Mother as we don't have main method for same. * Final batch
layout, title, folder, permalink, categories, tags
layout | title | folder | permalink | categories | tags | |
---|---|---|---|---|---|---|
pattern | Trampoline | trampoline | /patterns/trampoline/ | Behavioral |
|
Intent
Trampoline pattern is used for implementing algorithms recursively in Java without blowing the stack and to interleave the execution of functions without hard coding them together It is possible by representing a computation in one of 2 states : done | more (completed with result, or a reference to the reminder of the computation, something like the way a java.util.Supplier does).
Explanation
Trampoline pattern allows to define recursive algorithms by iterative loop.
Class diagram
Applicability
Use the Trampoline pattern when
- For implementing tail recursive function. This pattern allows to switch on a stackless operation.
- For interleaving the execution of two or more functions on the same thread.
Known uses(real world examples)
- Trampoline refers to using reflection to avoid using inner classes, for example in event listeners. The time overhead of a reflection call is traded for the space overhead of an inner class. Trampolines in Java usually involve the creation of a GenericListener to pass events to an outer class.