The course is part of this learning path
This course takes an in-depth look at how to use design patterns in your Java projects. We will then run through some example questions of what you could expect from the Oracle Certified Java EE exam.
- Understand what design patterns are
- Learn about the myriad of design patterns that you can use in your projects
This course is intended for anyone who already has basic knowledge of Java and now wants to learn about Java EE 6.
Basic knowledge of Java programming.
Hello, dear friends. In this video, we will examine the Business Delegate pattern. Let's begin. The Business Delegate pattern is one of the core Java EE design patterns. It's used in order to decouple or reduce the coupling between the presentation tier in business services. It's also required to hide the details of the implementation of the services, meaning it's needed to remove the function of lookup in the business tier code with the presentation tier code. It's basically used to reduce communication or remote lookup functionality to business tier code in presentation tier code. The Business Delegate pattern adds an abstraction layer between presentation and business tiers. By using the pattern, we gain loose coupling between the tiers and encapsulate knowledge on how to locate, connect to and interact with the business objects that make up the application.
As you can see, in the UML of iterator, there are three participants. BusinessDelegate is a single-entry point class for client entities to provide access to BusinessService methods. The BusinessService is a business tier component, such as an enterprise bean or a JMS component that provides the required service to the client. The BusinessDelegate uses the lookup service to locate the BusinessService. The lookup service encapsulates the implementation details of BusinessService lookup. The BusinessDelegate's role is to provide control and protection for the BusinessService. The BusinessDelegate can expose two types of constructors to clients. One type of request instantiates the BusinessDelegate without an ID while the other instantiates it with an ID where ID is a string version of the reference to a remote object such as EJBHome or EJBObject.
When initialized without an ID, the BusinessDelegate requests the service from the lookup service typically implemented as a service locator which returns the service factory such as EJBHome. The BusinessDelegate requests that the service factory locate, create, or remove a BusinessService such as an enterprise bean. BusinessDelegate reduces coupling between presentation-tier clients and BusinessServices. The BusinessDelegate hides the underlying implementation details of the BusinessService. Now, let's create a project using the Business Delegate pattern. Create a new project and name it BusinessDelegate. First, we need a BusinessService as interface. We will define the process method. Afterwards, let's define two concrete classes implementing this interface. EJB. We will override method. Now, JMS. Override for JMS. Let's define a lookup service. The lookup service object should provide the relative business implementations and business object access to the BusinessDelegate logic.
Now, we can define our BusinessDelegate. Also, we need a client to act as an access point to the BusinessServices. Let's use this pattern. First, define delegate. Now, send EJB to service. Now, set delegate to client. Change with JMS. Done. Let's look at the result. First process is EJB and the second one is JMS. We have now finished examining this pattern. In the next video, we will look into the Composite Entity Pattern. See you in the next video.
OAK Academy is made up of tech experts who have been in the sector for years and years and are deeply rooted in the tech world. They specialize in critical areas like cybersecurity, coding, IT, game development, app monetization, and mobile development.