Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Learning Java Functional Programming

You're reading from   Learning Java Functional Programming Create robust and maintainable Java applications using the functional style of programming

Arrow left icon
Product type Paperback
Published in Oct 2015
Publisher
ISBN-13 9781783558483
Length 296 pages
Edition 1st Edition
Languages
Arrow right icon
Authors (2):
Arrow left icon
Richard M. Reese Richard M. Reese
Author Profile Icon Richard M. Reese
Richard M. Reese
Richard M Reese Richard M Reese
Author Profile Icon Richard M Reese
Richard M Reese
Arrow right icon
View More author details
Toc

Table of Contents (11) Chapters Close

Preface 1. Getting Started with Functional Programming 2. Putting the Function in Functional Programming FREE CHAPTER 3. Function Composition and Fluent Interfaces 4. Streams and the Evaluation of Expressions 5. Recursion Techniques in Java 8 6. Optional and Monads 7. Supporting Design Patterns Using Functional Programming 8. Refactoring, Debugging, and Testing 9. Bringing It All Together Index

Implementing the template pattern


The template pattern is based around the idea that certain problems have structures that are reflected in a core method. This method uses the same set of operations to perform a task. This can be seen in a loading task where the basic steps to load a container is essentially the same whether the container is a box or a truck.

The steps are the same, such as prepared item to be loaded, but the specific preparation will vary depending on the container. A box may require that the item be wrapped in paper while the truck may require the application of a plastic wrap.

We will use a game engine to illustrate this template. The basic steps include:

  1. Rendering an image.

  2. Updating the game.

  3. Terminating the game when it is over.

Object-oriented solution to the template pattern

This approach uses an abstract Game class that contains a template method and abstract methods for the initialization, rendering, and updating steps. Its implementation follows where an infinite loop...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime