• Complain

Lucian-Paul Torje - Design Patterns and Best Practices in Java

Here you can read online Lucian-Paul Torje - Design Patterns and Best Practices in Java full text of the book (entire story) in english for free. Download pdf and epub, get meaning, cover and reviews about this ebook. year: 2018, publisher: Packt Publishing, genre: Computer. Description of the work, (preface) as well as reviews are available. Best literature library LitArk.com created for fans of good reading and offers a wide selection of genres:

Romance novel Science fiction Adventure Detective Science History Home and family Prose Art Politics Computer Non-fiction Religion Business Children Humor

Choose a favorite category and find really read worthwhile books. Enjoy immersion in the world of imagination, feel the emotions of the characters or learn something new for yourself, make an fascinating discovery.

Lucian-Paul Torje Design Patterns and Best Practices in Java

Design Patterns and Best Practices in Java: summary, description and annotation

We offer to read an annotation, description, summary or preface (depends on what the author of the book "Design Patterns and Best Practices in Java" wrote himself). If you haven't found the necessary information about the book — write in the comments, we will try to find it.

Create various design patterns to master the art of solving problems using Java

About This Book
  • This book demonstrates the shift from OOP to functional programming and covers reactive and functional patterns in a clear and step-by-step manner
  • All the design patterns come with a practical use case as part of the explanation, which will improve your productivity
  • Tackle all kinds of performance-related issues and streamline your development
Who This Book Is For

This book is for those who are familiar with Java development and want to be in the drivers seat when it comes to modern development techniques. Basic OOP Java programming experience and elementary familiarity with Java is expected.

What You Will Learn
  • Understand the OOP and FP paradigms
  • Explore the traditional Java design patterns
  • Get to know the new functional features of Java
  • See how design patterns are changed and affected by the new features
  • Discover what reactive programming is and why is it the natural augmentation of FP
  • Work with reactive design patterns and find the best ways to solve common problems using them
  • See the latest trends in architecture and the shift from MVC to serverless applications
  • Use best practices when working with the new features
In Detail

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. Well 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 Javas 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.

Style and approach

This book explains design patterns in a step-by-step manner with clear and concise code explanations.

Downloading the example code for this book You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly to you.

Lucian-Paul Torje: author's other books


Who wrote Design Patterns and Best Practices in Java? Find out the surname, the name of the author of the book and a list of all author's works by series.

Design Patterns and Best Practices in Java — read online for free the complete book (whole text) full work

Below is the text of the book, divided by pages. System saving the place of the last page read, allows you to conveniently read the book "Design Patterns and Best Practices in Java" online for free, without having to search again every time where you left off. Put a bookmark, and you can go to the page where you finished reading at any time.

Light

Font size:

Reset

Interval:

Bookmark:

Make
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 Controllerweb service - photo 1

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 apply to any initial level checks, data cleanups, validations, security requirements, such as authentication and authorization, and so on. Once this layer is satisfied, the request is accepted and processed.

The Service layer, also known as the applicationlayer, is responsible for providing different services, such as adding a record, sending emails, downloading a file, generating a report, and so on. In a small-scale application, we can merge the service layer with the web service layer, especially when we know that the service layer will only handle requests from the web. If the current service can be called from other services as well, it is better to keep the service separate from the web service or controller.

The Business layer holds all the business-related logic. For example, in an employee data management service, if the system is trying to promote an employee as manager, it is the responsibility of this layer to apply all the business checks, including whether the employee has relevant experience, whether they are already serving as a deputy manager, whether last year's appraisal rating matches with the required rules, and so on. Sometimes, if the application or service in question does not have a strong set of business rules, the business layer is merged with the application layer. On the other hand, you may want to further divide the business layer into sublayers in case your application demands strong implementation of business rules. Again, there is no fixed set of guidelines that you need to follow while implementing a layered design, and the implementation can change based on your application or service needs.

The Data access layer is the layer responsible for managing all data-related operations, such as fetching data, representing data in the required format, cleaning data, storing data, updating data, and so on. While creating this layer, we can use an object relational mapping (ORM) framework or create our own handlers. The idea here is to keep other layers free from worrying about data handling, that is, how data is being stored. Is it coming from another third-party service or being stored locally? These and similar concerns are the responsibility of this layer only.

Cross-cutting concerns are the concerns that each layer needs to handle; for example, each layer is responsible for checking whether the request is coming from the proper channel and no unauthorized request gets served. Each layer may want to record the entry and exit of a request by logging each message. These concerns can be handled through common utilities that are used and spread across the layers or can be handled by each layer independently. It is usually a good idea to keep these concerns independent of core business or application logic, using techniques such as aspects-oriented programming (AOP).

Polymorphism

In broad terms, polymorphism gives us an option to use the same interface for entities of different types. There are two major types of polymorphism, compile time and runtime. Say you have a Shape c lass that has two area methods. One returns the area of a circle and it accepts single integer; that is, the radius is input and it returns the area. Another method calculates the area of a rectangle and takes two inputs, length and breadth. The compiler can decide, based on the number of arguments in the call, which area method is to be called. This is the compile-time type of polymorphism.

There is a group of techies who consider only runtime polymorphism as real polymorphism. Runtime polymorphism, also sometimes known as subtyping polymorphism, comes into play when a subclass inherits a superclass and overrides its methods. In this case, the compiler cannot decide whether the subclass implementation or superclass implementation will be finally executed, and hence a decision is taken at runtime.

To elaborate, let's take our previous example and add a new method to the vehicle type to print the type and name of the object:

public String toString()
{
return "Vehicle:"+name;
}

We override the same method in the derived Car class:

public String toString()
{
return "Car:"+name;
}

Now we can see subtyping polymorphism in action. We create one Vehicle object and one Car object. We assign each object to a Vehicle variable type because a Car is also a Vehicle. Then we invoke the toString method for each of the objects. For vehicle1, which is an instance of the Vehicle class, it will invoke the Vehicle.toString() class. For vehicle2, which is an instance of the Car class, the toString method of the Car class will be invoked:

Vehicle vehicle1 = new Vehicle("A Vehicle");
Vehicle vehicle2 = new Car("A Car")
System.out.println(vehicle1.toString());
System.out.println(vehicle2.toString());
Asynchronous-communication pattern

While we are discussing the responsive pillar of reactive programming, another important pattern one needs to consider is the asynchronous-communication pattern. While the request-response pattern makes sure that all the requests get successful responses, it does not take care of the fact that some of the requests might take a large amount of time to respond. The asynchronous-communication pattern helps our application to remain responsive, even if we are doing bulk tasks. The way we achieve responsiveness or quick responses is by making the core-task execution asynchronous. Think of it as your code requesting a service to do a certain task, say, updating the data in a database; the service receives the data and immediately responds that it has received the data. Note that the actual writing to the database has not been done yet, but a success message is returned to the calling method.

A more relevant example would be when a service is required to do a complex task, such as generating an Excel report by calculating the tax liability for each employee, which needs to be calculated on the fly, based on the salary and tax details provided by each employee. So, when the tax-reporting service receives a request to generate such a report, it will simply return a response acknowledging receipt of the request and the UI will show a message to refresh the page after a few minutes to see the updated report link. In this way, we are not blocking the end user, and he/she can do other tasks while the report is being generated at the backend.

Next page
Light

Font size:

Reset

Interval:

Bookmark:

Make

Similar books «Design Patterns and Best Practices in Java»

Look at similar books to Design Patterns and Best Practices in Java. We have selected literature similar in name and meaning in the hope of providing readers with more options to find new, interesting, not yet read works.


Reviews about «Design Patterns and Best Practices in Java»

Discussion, reviews of the book Design Patterns and Best Practices in Java and just readers' own opinions. Leave your comments, write what you think about the work, its meaning or the main characters. Specify what exactly you liked and what you didn't like, and why you think so.