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

Model View Controller architecture


Another widely used criteria for organizing code is by following the Model View Controller (MVC) architectural design pattern. As the name suggests, we are thinking about organizing our application into three parts, namely a model, a view, and a controller. Following MVC helps us maintain a separation of concerns and allows us to better organize our code. Take a look at the following:

  • Model: A model is the representation of the data. Data is a critical part of any application. It is the responsibility of the model layer to organize and implement logic to manage and modify data properly. It takes care of any events that need to happen in case some data is modified. In short, the model has the core business implementation.
  • View: Another important part for any application is the view, that is, the part with which the end user interacts. The view is responsible for displaying information to the end user and taking inputs from the user. This layer needs to make...