Book Image

Design Patterns and Best Practices in Java

By : Kamalmeet Singh, Adrian Ianculescu, Lucian-Paul Torje
Book Image

Design Patterns and Best Practices in Java

By: Kamalmeet Singh, Adrian Ianculescu, Lucian-Paul Torje

Overview of this book

Having a knowledge of design patterns enables you, as a developer, to improve your code base, promote code reuse, and make the architecture more robust. As languages evolve, new features take time to fully understand before they are adopted en masse. The mission of this book is to ease the adoption of the latest trends and provide good practices for programmers. We focus on showing you the practical aspects of smarter coding in Java. We'll start off by going over object-oriented (OOP) and functional programming (FP) paradigms, moving on to describe the most frequently used design patterns in their classical format and explain how Java’s functional programming features are changing them. You will learn to enhance implementations by mixing OOP and FP, and finally get to know about the reactive programming model, where FP and OOP are used in conjunction with a view to writing better code. Gradually, the book will show you the latest trends in architecture, moving from MVC to microservices and serverless architecture. We will finish off by highlighting the new Java features and best practices. By the end of the book, you will be able to efficiently address common problems faced while developing applications and be comfortable working on scalable and maintainable projects of any size.
Table of Contents (15 chapters)
Title Page
Packt Upsell
Contributors
Preface
Index

Preface

Having knowledge of design patterns enables you as a developer to improve your code base, promote code reuse, and make the architecture more robust. As languages evolve, it takes time for new features to be fully understood before they are adopted en masse. The mission of this book is to ease the adoption of the latest trends and provide good practices for programmers.

Who this book is for

This book is for every Java developer who wants to write quality code. This book talks about a lot of best practices that quite often are missed by developers while coding. The book also covers many design patterns. Design patterns are nothing but best practices to solve particular problems that have been tried and tested by a developer community.

What this book covers

Chapter 1, From Object-Oriented to Functional Programming, gives an introduction to different programming paradigms associated with the Java language.

Chapter 2, Creational Patterns, introduces the first in a series of design patterns; that is, creational patterns. The chapter talks about various creational design patterns.

Chapter 3, Behavioral Patterns, talks about behavioral design patterns. It explains various design patterns to manage behavior of code and objects.

Chapter 4, Structural Patterns, introduces you to structural design patterns and explains various widely used design patterns to manage the structuring of objects.

Chapter 5, Functional Patterns, introduces readers to functional programming and patterns associated with it.

Chapter 6, Let's Get Reactive, introduces you to reactive programming and Java's implementation of it with examples.

Chapter 7, Reactive Design Patterns, further explores the pillars of reactive programming and design patterns associated with these pillars.

Chapter 8, Trends in Application Architecture – from MVC to Microservices and Serverless Applications, explores architectural patterns that have been tried and tested by developers over the years.

Chapter 9, Best Practices in Java, introduces us to the history of Java, best practices, and updates available in the latest versions of Java, and, finally, what is expected in future from Java.

To get the most out of this book

Readers with prior Java experience will be able to gain the most from this book. It is recommended that readers try to explore and play around with the code examples provided in various chapters.

Download the example code files

You can download the example code files for this book from your account at www.packtpub.com. If you purchased this book elsewhere, you can visit www.packtpub.com/support and register to have the files emailed directly to you.

You can download the code files by following these steps:

  1. Log in or register at www.packtpub.com.
  2. Select the SUPPORT tab.
  3. Click on Code Downloads & Errata.
  4. Enter the name of the book in the Search box and follow the onscreen instructions.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

  • WinRAR/7-Zip for Windows
  • Zipeg/iZip/UnRarX for Mac
  • 7-Zip/PeaZip for Linux

The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Design-Patterns-and-Best-Practices-in-Java. In case there's an update to the code, it will be updated on the existing GitHub repository.

We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Download the color images

We also provide a PDF file that has color images of the screenshots/diagrams used in this book. You can download it from http://www.packtpub.com/sites/default/files/downloads/DesignPatternsandBestPracticesinJava_ColorImages.pdf.

Conventions used

There are a number of text conventions used throughout this book.

CodeInText: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: "Make the getInstance method thread-safe by adding the synchronized keyword to its declaration."

A block of code is set as follows:

public class Car extends Vehicle
{
  public Car(String name)
  {
    super(name)
  }
}

Any command-line input or output is written as follows:

java --list-modules

Bold: Indicates a new term, an important word, or words that you see onscreen. For example, words in menus or dialog boxes appear in the text like this. Here is an example: "Before this change, you would need the complete Java Runtime Environment (JRE) as a whole to be loaded on a server or a machine to run the Java application."

Note

Warnings or important notes appear like this.

Note

Tips and tricks appear like this.

Get in touch

Feedback from our readers is always welcome.

General feedback: Email [email protected] and mention the book title in the subject of your message. If you have questions about any aspect of this book, please email us at [email protected].

Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you would report this to us. Please visit www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details.

Piracy: If you come across any illegal copies of our works in any form on the Internet, we would be grateful if you would provide us with the location address or website name. Please contact us at [email protected] with a link to the material.

If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit authors.packtpub.com.

Reviews

Please leave a review. Once you have read and used this book, why not leave a review on the site that you purchased it from? Potential readers can then see and use your unbiased opinion to make purchase decisions, we at Packt can understand what you think about our products, and our authors can see your feedback on their book. Thank you!

For more information about Packt, please visit packtpub.com.