Book Image

Practical Design Patterns for Java Developers

By : Miroslav Wengner
Book Image

Practical Design Patterns for Java Developers

By: Miroslav Wengner

Overview of this book

Design patterns are proven solutions to standard problems in software design and development, allowing you to create reusable, flexible, and maintainable code. This book enables you to upskill by understanding popular patterns to evolve into a proficient software developer. You’ll start by exploring the Java platform to understand and implement design patterns. Then, using various examples, you’ll create different types of vehicles or their parts to enable clarity in design pattern thinking, along with developing new vehicle instances using dedicated design patterns to make the process consistent. As you progress, you’ll find out how to extend vehicle functionalities and keep the code base structure and behavior clean and shiny. Concurrency plays an important role in application design, and you'll learn how to employ a such design patterns with the visualization of thread interaction. The concluding chapters will help you identify and understand anti-pattern utilization in the early stages of development to address refactoring smoothly. The book covers the use of Java 17+ features such as pattern matching, switch cases, and instances of enhancements to enable productivity. By the end of this book, you’ll have gained practical knowledge of design patterns in Java and be able to apply them to address common design problems.
Table of Contents (14 chapters)
1
Part 1: Design Patterns and Java Platform Functionalities
4
Part 2: Implementing Standard Design Patterns Using Java Programming
8
Part 3: Other Essential Patterns and Anti-Patterns

Executing isolated tasks with the scheduler pattern

An application behaving deterministically can play a critical role in its success. A scheduler pattern can help to achieve the desired goal.

Motivation

Although schedulers are sometimes poorly designed to keep the application busy, their main purpose is important. The importance of using patterns comes to light more with microservices or distributed approaches in which the system is required to behave predictably. The general goal is to determine when a specific task is performed so that the underlying resources are properly used or a budget estimate can be created for the required resources described in site reliability engineering.

Sample code

The following example brings us to temperature measurement. Every vehicle contains temperature sensors in a mechanical or digital form. Temperature sensors play a key role in vehicle operation (Example 6.13):

public static void main (String [] args) throws Exception {
 ...