
Practical Design Patterns for Java Developers: Hone your software design skills by implementing popular design patterns in Java
- Length: 266 pages
- Edition: 1
- Language: English
- Publisher: Packt Publishing
- Publication Date: 2023-02-03
- ISBN-10: 180461467X
- ISBN-13: 9781804614679
- Sales Rank: #2253367 (See Top 100 Books)
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.
Practical Design Patterns for Java Developers Foreword Contributors About the author About the reviewer Preface Who this book is for What this book covers To get the most out of this book Download the example code files Download the color images Conventions used Get in touch Share Your Thoughts Download a free PDF copy of this book Part 1: Design Patterns and Java Platform Functionalities Chapter 1: Getting into Software Design Patterns Technical requirements Code – from symbols to program Examining OOP and APIE Only exposing what’s required – encapsulation Inevitable evolution – inheritance Behavior on demand – polymorphism Standard features – abstraction Gluing parts to APIE Understanding the SOLID design principles The single-responsibility principle (SRP) – the engine is just an engine The open-closed principle (OCP) The Liskov Substitution Principle (LSP) – substitutability of classes The interface segregation principle (ISP) The dependency inversion principle (DIP) Significance of design patterns Reviewing what challenges design patterns solve Summary Questions Further reading 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 The JDK The JRE The JVM Reviewing GC and the Java memory model The JMM GC and automatic memory management Examining the core Java APIs Primitive data types and wrappers Working with the String API Introducing arrays Discovering a collection framework Math APIs Functional programming and Java Introducing lambdas and functional interfaces Using functional interfaces in lambda expressions 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 From a basic thread to executors Executing tasks 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 Motivation Finding it in the JDK Sample code Conclusion Creating objects from different families using the abstract factory pattern Motivation Finding it in the JDK Sample code Conclusion Instantiating complex objects with the builder pattern Motivation Finding it in the JDK Sample code Conclusion Cloning objects with the prototype pattern Motivation Finding it in the JDK Sample code Conclusion Ensuring only one instance with the singleton pattern Motivation Finding it in the JDK Sample code Conclusion Improving performance with the object pool pattern Motivation Finding it in the JDK Sample code Conclusion Initiating objects on demand with the lazy initialization pattern Motivation Finding it in the JDK Sample code Conclusion Reducing class dependencies with the dependency injection pattern Motivation Finding it in the JDK Sample code Conclusion Summary Questions Further reading Chapter 4: Applying Structural Design Patterns Technical requirements Incompatible object collaboration with the adapter pattern Motivation Finding it in the JDK Sample code Conclusion Decoupling and developing objects independently with the bridge pattern Motivation Finding it in the JDK Sample code Conclusion Treating objects the same way using the composite pattern Motivation Finding it in the JDK Sample code Conclusion Extending object functionality by using the decorator pattern Motivation Finding it in the JDK Sample code Conclusion Simplifying communication with the facade pattern Motivation Finding it in the JDK Sample code Conclusion Using conditions to select desired objects with the filter pattern Motivation Finding it in the JDK Sample code Conclusion Sharing objects across an application with the flyweight pattern Motivation Finding it in the JDK Sample code Conclusion Handling requests with the front-controller pattern Motivation Finding it in the JDK Sample code Conclusion Identifying instances using the marker pattern Motivation Finding it in the JDK Sample code Conclusion Exploring the concept of modules with the module pattern Motivation Finding it in the JDK Sample code Conclusion Providing a placeholder for an object using the proxy pattern Motivation Finding it in the JDK Sample code Conclusion Discovering multiple inheritance in Java with the twin pattern Motivation Sample code Conclusion Summary Questions Further reading Chapter 5: Behavioral Design Patterns Technical requirements Limiting expensive initialization using the caching pattern Motivation Finding it in the JDK Sample code Conclusion Handling events using the chain of responsibility pattern Motivation Finding it in the JDK Sample code Conclusion Turning information into action with the command pattern Motivation Finding it in the JDK Sample code Conclusion Giving meaning to the context using the interpreter pattern Motivation Finding it in the JDK Sample code Conclusion Checking all the elements with the iterator pattern Motivation Finding it in the JDK Sample code Conclusion Utilizing the mediator pattern for information exchange Motivation Finding it in the JDK Sample code Conclusion Restoring the desired state with the memento pattern Motivation Finding it in the JDK Sample code Conclusion Avoiding a null pointer exception state with the null object pattern Motivation Finding it in the JDK Sample code Conclusion Keeping all interested parties informed using the observer pattern Motivation Finding it in the JDK Sample code Conclusion Dealing with instance stages by using the pipeline pattern Motivation Finding it in the JDK Sample code Conclusion Changing object behavior with the state pattern Motivation Finding it in the JDK Sample code Conclusion Using the strategy pattern to change object behavior Motivation Finding it in the JDK Sample code Conclusion Standardizing processes with the template pattern Motivation Finding it in the JDK Sample code Conclusion Executing code based on the object type using the visitor pattern Motivation Finding it in the JDK Sample code Conclusion 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 Motivation Sample code Conclusion Non-blocking tasks using async method invocation pattern Motivation Sample code Conclusion Delay execution until the previous task is completed with the balking pattern Motivation Sample code Conclusion Providing a unique object instance with a double-checked locking pattern Motivation Sample code Conclusion Using purposeful thread blocking via a read-write lock pattern Motivation Sample code Conclusion Decoupling the execution logic with a producer-consumer pattern Motivation Sample code Conclusion Executing isolated tasks with the scheduler pattern Motivation Sample code Conclusion Effective thread utilization using a thread-pool pattern Motivation Sample code Conclusion Summary Questions Further reading Answers Chapter 7: Understanding Common Anti-Patterns Technical requirements What anti-patterns are and how to identify them Theoretical principles challenges Collecting technical debt as a bottleneck Inappropriately squeezing the capabilities of the Java platform Selecting the right tool Conclusion of the code smell anti-pattern Examining typical software anti-patterns Spaghetti code Cut and paste programming Blob Lava flow Functional decomposition Boat anchor Conclusion Understanding software architecture anti-patterns Golden hammer Continuous obsolescence Input kludge Working in a minefield Ambiguous viewpoint Poltergeists Dead end Conclusion Summary Further reading Assessments Chapter 1 – Getting into Software Design Patterns Chapter 2 – Discovering the Java Platform for Design Patterns Chapter 3 – Working with Creational Design Patterns Chapter 4 – Applying Structural Design Patterns Chapter 5 – Behavioral Design Patterns Chapter 6 – Concurrency Design Patterns Index Why subscribe? Other Books You May Enjoy Packt is searching for authors like you Share Your Thoughts Download a free PDF copy of this book
How to download source code?
1. Go to: https://github.com/PacktPublishing
2. In the Find a repository… box, search the book title: Practical Design Patterns for Java Developers: Hone your software design skills by implementing popular design patterns in Java
, sometime you may not get the results, please search the main title.
3. Click the book title in the search results.
3. Click Code to download.
1. Disable the AdBlock plugin. Otherwise, you may not get any links.
2. Solve the CAPTCHA.
3. Click download link.
4. Lead to download server to download.