Java EE 8 Design Patterns and Best Practices by Rhuan Rocha

Java EE 8 Design Patterns and Best Practices by Rhuan Rocha

Author:Rhuan Rocha
Language: eng
Format: epub, pdf
Tags: COM051280 - COMPUTERS / Programming Languages / Java, COM051010 - COMPUTERS / Programming Languages / General, COM048000 - COMPUTERS / Systems Architecture / Distributed Systems and Computing
Publisher: Packt Publishing
Published: 2018-08-09T10:35:51+00:00


Summary

In this chapter, we have seen that interceptors and decorators are the platforms through which the JEE platform provides aspect-oriented programming. Interceptors are used to interpose the invocation of some method or life cycle events that occur in an associated target class. The interceptor takes care of technical tasks, called crosscutting tasks, that are repeated throughout an application, such as logging, auditing, and exception handling. These tasks are separate from business logic, and it's a good idea to put the interceptor in a separate class for easy maintenance.

We learned how the classic interceptor mechanism works for EJB, as well as the CDI inspector mechanism, which can intercept any managed bean and not just EJB-managed beans.

While the interceptor takes care of the technical tasks, we can add functionality to the existing business logic with the decorators. We learned that the decorator pattern is a well-known structural design pattern. A decorator is a type of interceptor for business classes, and is used when we want to add functionality to a business class while also keeping it intact.

The use of interceptor and decorators promotes low coupling and easy maintenance. However, we must use them carefully. For example, with regards to decorators, we should avoid excessively spreading them through the application. Excessive decentralization can cause an inverse effect and worsen code maintenance.

An interceptor belongs to the same transactional context of the business class that it interposes. As an interceptor only deals with technical issues, tasks related to it cannot influence the execution of business logic. Consequently, errors generated in technical tasks cannot be thrown to the business logic. In a similar way, the execution time of these tasks cannot compose the execution time of business logic.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.