ebook img

Java EE 8 Design Patterns and Best Practices PDF

304 Pages·2020·10.284 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Java EE 8 Design Patterns and Best Practices

Java EE 8 Design Patterns and Best Practices Build enterprise-ready scalable applications with architectural design patterns Rhuan Rocha João Purificação BIRMINGHAM - MUMBAI Java EE 8 Design Patterns and Best Practices Copyright © 2018 Packt Publishing All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews. Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the authors, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book. Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information. Commissioning Editor: Richa Tripathi Acquisition Editor: Alok Dhuri Content Development Editor: Akshada Iyer Technical Editor: Mehul Singh Copy Editor: Safis Editing Project Coordinator: Prajakta Naik Proofreader: Safis Editing Indexer: Pratik Shirodkar Graphics: Jisha Chirayil Production Coordinator: Shraddha Falebhai First published: August 2018 Production reference: 1080818 Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK. ISBN 978-1-78883-062-1 www.packtpub.com To my Aunt, Vanessa Rocha, for teaching me to have a calm look and observe the facts more clearly. To my mother, Ivonete Rocha, for her sacrifices and power. - Rhuan Rocha To my two daughters, Carolina and Beatriz, who give me the energy to walk even further; to my father, João Lobato, for his great wisdom and intelligence; and to my mother, Dinah, for her love and affection. - João Purificação mapt.io Mapt is an online digital library that gives you full access to over 5,000 books and videos, as well as industry leading tools to help you plan your personal development and advance your career. For more information, please visit our website. Why subscribe? Spend less time learning and more time coding with practical eBooks and Videos from over 4,000 industry professionals Improve your learning with Skill Plans built especially for you Get a free eBook or video every month Mapt is fully searchable Copy and paste, print, and bookmark content PacktPub.com Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at [email protected] for more details. At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters, and receive exclusive discounts and offers on Packt books and eBooks. Contributors About the authors Rhuan Rocha is from Brazil and has experience with development using the Java language and Java EE. Currently, he works as senior Middleware consultant in a partnership between Red Hat and FábricaDS, and he applies Red Hat solutions using Red Hat Middlewares. Furthermore, he has 8 years, experience with Java development and Java EE development, developing enterprise applications and government applications. João Purificação is an electronic engineer from Brazil with a master's in systems engineering. He started working with software development as a C and C ++ programmer. He has worked on the analysis, development, and architecture of Java-based enterprise applications. As a Java/JavaEE consultant, he has participated in the development and architecture of applications for private and government companies. He currently works as a senior architect at Resource IT, a company based in São Paulo. About the reviewer Kamalmeet Singh got his first taste of programming at the age of 15, and he immediately fell in love with it. After spending over 14 years in the IT Industry, Kamal has matured into an ace developer and a technical architect. He is also the coauthor of a book on Design Patterns and Best Practices in Java. The technologies he works with range from cloud computing, machine learning, augmented reality, serverless applications, to microservices and so on. Packt is searching for authors like you If you're interested in becoming an author for Packt, please visit authors.packtpub.com and apply today. We have worked with thousands of developers and tech professionals, just like you, to help them share their insight with the global tech community. You can make a general application, apply for a specific hot topic that we are recruiting an author for, or submit your own idea. Table of Contents Preface 1 Chapter 1: Introduction to Design Patterns 8 Explaining design patterns 9 Explaining the Gang of Four design patterns 9 The catalog of Gang of Four design patterns 11 Understanding the advantages of design patterns 13 Understanding the basic design patterns of the Java world 14 Explaining Singleton 14 Explaining Abstract Factory 15 Explaining Facade 17 Explaining Iterator 17 Explaining Proxy 18 Explaining enterprise patterns 19 Defining the difference between design patterns and enterprise patterns 20 Summary 21 Chapter 2: Presentation Patterns 22 Explaining the presentation tier 22 Explaining intercepting filter pattern 24 Implementing the intercepting filter pattern using Java EE 8 25 Implementing LogAccessFilter 25 Implementing LogBrowserFilter 27 Deciding filter mapping 29 Explaining the FrontController pattern 30 Implementing FrontController 31 Implementing the commands 33 The application controller pattern 33 Implementing DownloadFrontController 34 Implementing DownloadApplicationController 36 Implementing commands 39 The difference between the application controller and front controller patterns 42 Summary 42 Chapter 3: Business Patterns 43 Understanding the business tier 43 Explaining the Business Delegate pattern 45 Client tier, presentation tier, and business tier 45 Table of Contents Layers 45 Tiers 47 The classic Business Delegate pattern scenario 48 The benefits of the Business Delegate pattern 51 Business Delegate – obsolete or not 52 Explaining the Session Façade pattern 53 Benefits of Session Façade 54 Implementing the Session Façade pattern in JEE 55 The classic Session Façade pattern scenario 55 Implementing the Session Façade pattern 58 Explaining the business-object pattern 70 Applications with complex business rules 71 Motivation for using the business-object pattern 73 Benefits of business-object pattern usage 73 Implementing the business-object pattern 75 Summary 78 Chapter 4: Integration Patterns 80 Explaining the concept of the integration tier 80 Explaining the concept of the data-access object pattern 81 Implementing the data-access object pattern 82 Implementing the entity with JPA 83 Implementing DAO 85 Explaining the concept of the domain-store pattern 88 Implementing the domain-store pattern 90 Implementing the PersistenceManagerFactory class 91 Implementing the PersistenceManager class 92 Implementing the EmployeeStoreManager class 95 Implementing the StageManager interface 96 Implementing the TransactionFactory class 98 Implementing the Transaction class 99 Implementing the EmployeeBusiness class 100 Explaining the concept of the service-activator pattern 101 Java Message Service (JMS) 102 EJB asynchronous methods 104 Asynchronous events – producers and observers 104 Implementing the service-activator pattern 106 Implementing sending and receiving messages with JMS 106 Implementing the EJB asynchronous methods 107 Implementing asynchronous events – producers and observers 108 Summary 109 Chapter 5: Aspect-Oriented Programming and Design Patterns 110 Aspect-oriented programming 111 Compile-time versus run-time AOP 111 AOP in JEE scenario – the interceptor 112 [ ii ] Table of Contents A brief word about CDI and beans 113 The bean 113 Managed beans in CDI 114 Loose coupling 114 Interceptors in the JEE platform 115 EJB interceptor implementation 117 Intercepting method invocation 120 Interceptor class and multiple method interceptors 121 Intercepting life cycle callback events 122 CDI interceptor implementation 125 Decorator 128 The decorator pattern 128 The decorator in a JEE scenario 130 Decorator implementation 131 Summary 134 Chapter 6: Reactive Patterns 135 Explaining the concept of an event in CDI 137 Implementing an event in CDI 138 Implementing the FileUploadResource class 138 Bean sent on the event 139 Qualifier to select the JpgHandler observer to react to an event 139 Qualifier to select the PdfHandler observer to react to an event 140 Qualifier to select the ZipHandler observer to react to an event 140 The FIleUploadResource class 141 Implementing observers 143 Explaining the concept of an asynchronous EJB method 146 Difference between an asynchronous EJB method and an event in CDI 146 Implementing an asynchronous EJB method 147 Implementing EJBs 147 Implementing the FileUploadResource class 150 Calling an asynchronous EJB method to save a PDF 151 Calling an asynchronous EJB method to save a JPG 152 Calling an asynchronous EJB method to save a ZIP 152 Explaining the concept of an asynchronous REST service 152 Implementing an asynchronous REST service 153 Implementing the EJBs 153 Implementing the FileUploadResource class 155 Implementing the client API 159 Summary 160 Chapter 7: Microservice Patterns 162 Explaining microservices patterns 162 Inside a monolithic application 164 Difficulty in implementing new features and fixing bugs 166 Long application startup time 166 Inefficient continuous deployment 166 Low reliability 167 [ iii ]

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.