Java EE 8 Design Patterns and Best Practices

Book description

Get the deep insights you need to master efficient architectural design considerations and solve common design problems in your enterprise applications.

Key Features

  • The benefits and applicability of using different design patterns in JAVA EE
  • Learn best practices to solve common design and architectural challenges
  • Choose the right patterns to improve the efficiency of your programs

Book Description

Patterns are essential design tools for Java developers. Java EE Design Patterns and Best Practices helps developers attain better code quality and progress to higher levels of architectural creativity by examining the purpose of each available pattern and demonstrating its implementation with various code examples. This book will take you through a number of patterns and their Java EE-specific implementations.

In the beginning, you will learn the foundation for, and importance of, design patterns in Java EE, and then will move on to implement various patterns on the presentation tier, business tier, and integration tier. Further, you will explore the patterns involved in Aspect-Oriented Programming (AOP) and take a closer look at reactive patterns. Moving on, you will be introduced to modern architectural patterns involved in composing microservices and cloud-native applications. You will get acquainted with security patterns and operational patterns involved in scaling and monitoring, along with some patterns involved in deployment.

By the end of the book, you will be able to efficiently address common problems faced when developing applications and will be comfortable working on scalable and maintainable projects of any size.

What you will learn

  • Implement presentation layers, such as the front controller pattern
  • Understand the business tier and implement the business delegate pattern
  • Master the implementation of AOP
  • Get involved with asynchronous EJB methods and REST services
  • Involve key patterns in the adoption of microservices architecture
  • Manage performance and scalability for enterprise-level applications

Who this book is for

Java developers who are comfortable with programming in Java and now want to learn how to implement design patterns to create robust, reusable and easily maintainable apps.

Table of contents

  1. Title Page
  2. Copyright and Credits
    1. Java EE 8 Design Patterns and Best Practices
  3. Dedication
  4. Packt Upsell
    1. Why subscribe?
    2. PacktPub.com
  5. Contributors
    1. About the authors
    2. About the reviewer
    3. Packt is searching for authors like you
  6. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
      1. Download the example code files
      2. Download the color images
      3. Conventions used
    4. Get in touch
      1. Reviews
  7. Introduction to Design Patterns
    1. Explaining design patterns
      1. Explaining the Gang of Four design patterns
        1. The catalog of Gang of Four design patterns
    2. Understanding the advantages of design patterns
    3. Understanding the basic design patterns of the Java world
      1. Explaining Singleton
      2. Explaining Abstract Factory
      3. Explaining Facade
      4. Explaining Iterator
      5. Explaining Proxy
    4. Explaining enterprise patterns
    5. Defining the difference between design patterns and enterprise patterns
    6. Summary
  8. Presentation Patterns
    1. Explaining the presentation tier
    2. Explaining intercepting filter pattern
    3. Implementing the intercepting filter pattern using Java EE 8
      1. Implementing LogAccessFilter
      2. Implementing LogBrowserFilter
      3. Deciding filter mapping
    4. Explaining the FrontController pattern
      1. Implementing FrontController
      2. Implementing the commands
    5. The application controller pattern
      1. Implementing DownloadFrontController
      2. Implementing DownloadApplicationController
      3. Implementing commands
      4. The difference between the application controller and front controller patterns
    6. Summary
  9. Business Patterns
    1. Understanding the business tier
    2. Explaining the Business Delegate pattern
      1. Client tier, presentation tier, and business tier
        1. Layers
        2. Tiers
      2. The classic Business Delegate pattern scenario
      3. The benefits of the Business Delegate pattern
        1. Business Delegate – obsolete or not
    3. Explaining the Session Façade pattern
      1. Benefits of Session Façade
      2. Implementing the Session Façade pattern in JEE
      3. The classic Session Façade pattern scenario
    4. Implementing the Session Façade pattern
    5. Explaining the business-object pattern
      1. Applications with complex business rules
        1. Motivation for using the business-object pattern
        2. Benefits of business-object pattern usage
    6. Implementing the business-object pattern
    7. Summary
  10. Integration Patterns
    1. Explaining the concept of the integration tier
    2. Explaining the concept of the data-access object pattern
    3. Implementing the data-access object pattern
      1. Implementing the entity with JPA
      2. Implementing DAO
    4. Explaining the concept of the domain-store pattern
    5. Implementing the domain-store pattern
      1. Implementing the PersistenceManagerFactory class
      2. Implementing the PersistenceManager class
      3. Implementing the EmployeeStoreManager class
      4. Implementing the StageManager interface
      5. Implementing the TransactionFactory class
      6. Implementing the Transaction class
      7. Implementing the EmployeeBusiness class
    6. Explaining the concept of the service-activator pattern
      1. Java Message Service (JMS)
      2. EJB asynchronous methods
      3. Asynchronous events – producers and observers
    7. Implementing the service-activator pattern
      1. Implementing sending and receiving messages with JMS
      2. Implementing the EJB asynchronous methods
      3. Implementing asynchronous events – producers and observers
    8. Summary
  11. Aspect-Oriented Programming and Design Patterns
    1. Aspect-oriented programming
      1. Compile-time versus run-time AOP
      2. AOP in JEE scenario – the interceptor
        1. A brief word about CDI and beans
        2. The bean
          1. Managed beans in CDI
        3. Loose coupling
        4. Interceptors in the JEE platform
        5. EJB interceptor implementation
          1. Intercepting method invocation
          2. Interceptor class and multiple method interceptors
          3. Intercepting life cycle callback events 
        6. CDI interceptor implementation
      3. Decorator 
        1. The decorator pattern
        2. The decorator in a JEE scenario
        3. Decorator implementation 
    2. Summary
  12. Reactive Patterns
    1. Explaining the concept of an event in CDI
    2. Implementing an event in CDI
      1. Implementing the FileUploadResource class
        1. Bean sent on the event
        2. Qualifier to select the JpgHandler observer to react to an event 
        3. Qualifier to select the PdfHandler observer to react to an event 
        4. Qualifier to select the ZipHandler observer to react to an event 
        5. The FIleUploadResource class
      2. Implementing observers
    3. Explaining the concept of an asynchronous EJB method
      1. Difference between an asynchronous EJB method and an event in CDI
    4. Implementing an asynchronous EJB method
    5. Implementing EJBs
      1. Implementing the FileUploadResource class
        1. Calling an asynchronous EJB method to save a PDF
        2. Calling an asynchronous EJB method to save a JPG
        3. Calling an asynchronous EJB method to save a ZIP
    6. Explaining the concept of an asynchronous REST service
    7. Implementing an asynchronous REST service
      1. Implementing the EJBs 
      2. Implementing the FileUploadResource class
      3. Implementing the client API
    8. Summary
  13. Microservice Patterns
    1. Explaining microservices patterns
      1. Inside a monolithic application
        1. Difficulty in implementing new features and fixing bugs
        2. Long application startup time 
        3. Inefficient continuous deployment
        4. Low reliability
        5. Difficulty using new frameworks and technologies
      2. The scale cube
      3. What microservices actually are
        1. Microservices are not a silver bullet
    2. Explaining how microservices architecture works
      1. The application is decomposed into smaller components
      2. Multitask teams
      3. Product focus
      4. Simpler and smarter processing
      5. Decentralized governance of libraries and APIs
      6. Single responsibility principle
      7. Fault tolerance
      8. Evolutionary systems
      9. Decentralized data
    3. Explaining when to use microservices architecture
      1. How to decompose an application into microservices
        1. Identifying microservices
        2. Taking care of the process of extracting application modules that are candidates for microservices
        3. Establishing a hexagonal model for the application
    4. Advantages and drawbacks of a microservices-based application
    5. Microservices architecture patterns
      1. Aggregator pattern
      2. Proxy pattern
      3. Chained pattern
      4. Branch pattern
      5. Asynchronous pattern
    6. Implementing microservices
    7. Summary
  14. Cloud-Native Application Patterns
    1. Explaining the concept of cloud-native applications
    2. Explaining the goals of the cloud-native application
    3. Explaining the cloud design patterns
      1. Composite application (microservices)
      2. Abstraction
      3. Twelve-factor
        1. Codebase
        2. Dependencies
        3. Config
        4. Backing services
        5. Build, release, run
        6. Processes
        7. Port-binding
        8. Concurrency
        9. Disposability
        10. Dev/prod parity
        11. Logs
        12. Admin processes
      4. The API Gateway
      5. The service-registry pattern
      6. Config server
      7. The circuit-breaker pattern
        1. The circuit-breaker mechanism
    4. Summary
  15. Security Patterns
    1. Explaining the concept of security patterns
    2. Explaining the concept of the single-sign-on pattern
    3. Implementing the single-sign-on pattern
      1. Implementing the AuthenticationResource class
      2. Implementing the App1 and App2 classes
    4. Explaining the authentication mechanism
      1. Explaining basic authentication
      2. Explaining form authentication
      3. Explaining digest authentication
      4. Explaining client authentication
      5. Explaining mutual authentication
      6. When to use the deployment descriptor, annotation, or programmatic configuration
    5. Implementing the authentication mechanism
      1. Implementing the web.xml file
      2. Implementing the HelloWorld class
      3. Implementing the HelloWordServlet class
    6. Explaining the authentication interceptor
    7. Implementing the authentication interceptor
      1. Implementing the CDI interceptor
      2. Implementing the JAX-RS resource
    8. Summary
  16. Deployment Patterns
    1. Explaining the concept of deployment patterns
    2. Explaining the concept of canary deployment
      1. Defining the canary servers
      2. Deploying the application to canary servers
      3. Testing the application and verifying whether it satisfies our criteria
      4. Deploying the application to remaining servers
    3. Explaining the concept of blue/green deployment
      1. Defining the group of servers to receive the first deployment
      2. Deploying the application to a group of servers
      3. Deploying the application to the remaining server
    4. Explaining the concept of A/B testing
      1. Defining a group of end users
      2. Defining the servers to receive a new version
      3. Deploying the new version
      4. Evaluating the impact of a new version
    5. Explaining the concept of continuous deployment
    6. Summary
  17. Operational Patterns
    1. Explaining the concept of operational patterns
    2. Explaining the concept of performance and scalability patterns
      1. The cache-aside pattern
      2. When to use the cache-aside pattern
        1. The lifetime of cached data
        2. Evicting data
        3. Priming the cache
        4. Consistency
        5. Local (in-memory) caching
      3. The CQRS pattern
      4. When to use the CQRS pattern
      5. The event sourcing pattern
        1. Understanding the event of event sourcing 
        2. Promoting performance
        3. Promoting decoupling
        4. Promoting scalability
        5. Promoting auditing
      6. Explaining the index table pattern
      7. The materialized view pattern
        1. Rebuilding the materialized view
        2. When to use the materialized view pattern
      8. Explaining the sharding pattern
        1. When to use the sharding pattern
    3. Explaining the concept of management and monitoring patterns
      1. The ambassador pattern
        1. When to use the ambassador pattern
      2. Explaining the health endpoint monitoring pattern
        1. When to use the health endpoint monitoring pattern
      3. Explaining the external configuration store pattern
        1. When to use the external configuration store pattern
    4. Summary
  18. MicroProfile
    1. Explaining the Eclipse MicroProfile project approach
      1. Eclipse MicroProfile Config 1.3
      2. Eclipse MicroProfile Fault Tolerance 1.1
      3. Eclipse MicroProfile Health Check 1.0
      4. Eclipse MicroProfile JWT authentication 1.1
      5. Eclipse MicroProfile Metrics 1.1
      6. Eclipse MicroProfile OpenAPI 1.0
      7. Eclipse MicroProfile OpenTracing 1.1
      8. Eclipse MicroProfile REST Client 1.1
      9. CDI 2.0
      10. Common annotations 1.3
      11. JAX-RS 2.1
      12. JSON-B 1.0
      13. JSON-P 1.1
      14. Why should we use the MicroProfile project?
      15. Community
      16. Future work
    2. Summary
  19. Other Books You May Enjoy
    1. Leave a review - let other readers know what you think

Product information

  • Title: Java EE 8 Design Patterns and Best Practices
  • Author(s): Rhuan Rocha, Joao Purificacao
  • Release date: August 2018
  • Publisher(s): Packt Publishing
  • ISBN: 9781788830621