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

Layered architecture


We try to divide our code and implementation into different layers, and each layer will have a fixed responsibility. There is no fixed set of layering that can be applied to all the projects, so you may need to think about what kind of layering will work for the project in hand.

The following diagram shows a common layered architecture, which can be a good starting point when thinking about a typical web application:

The design has the following layers:

  • Presentation layer
  • Controller/web service layer
  • Service layer
  • Business layer
  • Data access layer

The Presentation layer is the layer that holds your UI, that is, HTML/JavaScript/JSPs, and so on. This is the layer that the end user can directly interact with.

The Controller/web service layer is the entry point for a request from a third party. This request can come from the presentation layer (mostly) or from another service; for example, a mobile or desktop application. As this is the entry point for any request, this layer will...