Book description
Unravel the power of Java design patterns by learning where to apply them effectively to solve specific software design and development problems
Key Features
- Decouple logic across objects with dependency injection by creating various vehicles with features
- Finalize vehicle construction by chaining handlers using the Chain of Responsibility Pattern
- Plan and execute an advanced vehicle sensor initiation with the Scheduler Pattern
Book Description
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.
What you will learn
- Understand the most common problems that can be solved using Java design patterns
- Uncover Java building elements, their usages, and concurrency possibilities
- Optimize a vehicle memory footprint with the Flyweight Pattern
- Explore one-to-many relations between instances with the observer pattern
- Discover how to route vehicle messages by using the visitor pattern
- Utilize and control vehicle resources with the thread-pool pattern
- Understand the penalties caused by anti-patterns in software design
Who this book is for
If you are an intermediate-level Java developer or software architect looking to learn the practical implementation of software design patterns in Java, then this book is for you. No prior knowledge of design patterns is required, but an understanding of Java programming is necessary.
Table of contents
- Practical Design Patterns for Java Developers
- Foreword
- Contributors
- About the author
- About the reviewer
- Preface
- Part 1: Design Patterns and Java Platform Functionalities
- Chapter 1: Getting into Software Design Patterns
-
Chapter 2: Discovering the Java Platform for Design Patterns
- Technical requirements
- Knocking on Java’s door
- Exploring the model and functionality of the Java platform
- Reviewing GC and the Java memory model
- Examining the core Java APIs
- Functional programming and Java
- Getting to grips with the Java Module System
-
A quick review of Java features from 11 to 17+
- The local variable syntax for lambda parameters (Java SE 11, JEP-323)
- Switch expressions (Java SE 14, JEP-361)
- Text blocks (Java SE 15, JEP-378)
- Pattern matching for instanceof (Java SE 16, JEP-394)
- Records (Java SE 16, JEP-395)
- Sealed classes (Java SE 17, JEP-409)
- UTF-8 by default (Java SE 18, JEP-400)
- Pattern matching for switch (Java SE 18, Second Preview, JEP-420)
- Understanding Java concurrency
- Summary
- Questions
- Further reading
- Part 2: Implementing Standard Design Patterns Using Java Programming
-
Chapter 3: Working with Creational Design Patterns
- Technical requirements
- It all starts with a class that becomes an object
- Creating objects based on input with the factory method pattern
- Creating objects from different families using the abstract factory pattern
- Instantiating complex objects with the builder pattern
- Cloning objects with the prototype pattern
- Ensuring only one instance with the singleton pattern
- Improving performance with the object pool pattern
- Initiating objects on demand with the lazy initialization pattern
- Reducing class dependencies with the dependency injection pattern
- Summary
- Questions
- Further reading
-
Chapter 4: Applying Structural Design Patterns
- Technical requirements
- Incompatible object collaboration with the adapter pattern
- Decoupling and developing objects independently with the bridge pattern
- Treating objects the same way using the composite pattern
- Extending object functionality by using the decorator pattern
- Simplifying communication with the facade pattern
- Using conditions to select desired objects with the filter pattern
- Sharing objects across an application with the flyweight pattern
- Handling requests with the front-controller pattern
- Identifying instances using the marker pattern
- Exploring the concept of modules with the module pattern
- Providing a placeholder for an object using the proxy pattern
- Discovering multiple inheritance in Java with the twin pattern
- Summary
- Questions
- Further reading
-
Chapter 5: Behavioral Design Patterns
- Technical requirements
- Limiting expensive initialization using the caching pattern
- Handling events using the chain of responsibility pattern
- Turning information into action with the command pattern
- Giving meaning to the context using the interpreter pattern
- Checking all the elements with the iterator pattern
- Utilizing the mediator pattern for information exchange
- Restoring the desired state with the memento pattern
- Avoiding a null pointer exception state with the null object pattern
- Keeping all interested parties informed using the observer pattern
- Dealing with instance stages by using the pipeline pattern
- Changing object behavior with the state pattern
- Using the strategy pattern to change object behavior
- Standardizing processes with the template pattern
- Executing code based on the object type using the visitor pattern
- Summary
- Questions
- Further reading
- Part 3: Other Essential Patterns and Anti-Patterns
-
Chapter 6: Concurrency Design Patterns
- Technical requirements
- Decoupling a method execution with an active object pattern
- Non-blocking tasks using async method invocation pattern
- Delay execution until the previous task is completed with the balking pattern
- Providing a unique object instance with a double-checked locking pattern
- Using purposeful thread blocking via a read-write lock pattern
- Decoupling the execution logic with a producer-consumer pattern
- Executing isolated tasks with the scheduler pattern
- Effective thread utilization using a thread-pool pattern
- Summary
- Questions
- Further reading
- Answers
- Chapter 7: Understanding Common Anti-Patterns
- Assessments
- Index
- Other Books You May Enjoy
Product information
- Title: Practical Design Patterns for Java Developers
- Author(s):
- Release date: February 2023
- Publisher(s): Packt Publishing
- ISBN: 9781804614679
You might also like
book
Design Patterns and Best Practices in Java
Create various design patterns to master the art of solving problems using Java About This Book …
video
Design Patterns and SOLID Principles with Java
Write maintainable, extensible, and cloud-ready code in Java, using design patterns and SOLID principles About This …
book
Java Design Patterns: A Hands-On Experience with Real-World Examples
Use the step-by-step approach of this book to learn and implement design patterns in real-world applications. …
book
Java Design Patterns: A Hands-On Experience with Real-World Examples
Get hands-on experience implementing 26 of the most common design patterns using Java and Eclipse. In …