Book Image

Hands-On Design Patterns with Java

By : Dr. Edward Lavieri
2 (1)
Book Image

Hands-On Design Patterns with Java

2 (1)
By: Dr. Edward Lavieri

Overview of this book

Java design patterns are reusable and proven solutions to software design problems. This book covers over 60 battle-tested design patterns used by developers to create functional, reusable, and flexible software. Hands-On Design Patterns with Java starts with an introduction to the Unified Modeling Language (UML), and delves into class and object diagrams with the help of detailed examples. You'll study concepts and approaches to object-oriented programming (OOP) and OOP design patterns to build robust applications. As you advance, you'll explore the categories of GOF design patterns, such as behavioral, creational, and structural, that help you improve code readability and enable large-scale reuse of software. You’ll also discover how to work effectively with microservices and serverless architectures by using cloud design patterns, each of which is thoroughly explained and accompanied by real-world programming solutions. By the end of the book, you’ll be able to speed up your software development process using the right design patterns, and you’ll be comfortable working on scalable and maintainable projects of any size.
Table of Contents (15 chapters)
Free Chapter
Section 1: Introducing Design Patterns
Section 2: Original Design Patterns
Section 3: New Design Patterns

Understanding the memoization design pattern

The memoization functional design pattern stores the results of key functions so that overall processing efficiency is increased. When there are specific processes that have the same output each time they are invoked, it is less costly, from a processing time perspective, to cache the results instead of recalculating them each time.

The Fibonacci sequence is often used to demonstrate memoization, so it shall be used here as well.

Fibonacci numbers are a mathematical construct where each number is the sum of the two preceding numbers. The Fibonacci sequence starts with the numbers 0 and 1.

Let's start by looking at a standard implementation of the Fibonacci sequence. Here is the source code:

public class FibonacciTest1 {

public static int computeFibonacciNumber(int number) {

// this checks for the fibonacci base of 0 and...