Now that you understand the rationale and intent of patterns, how can you apply them to your J2EE applications? To do this, you must understand the J2EE design context, and you must also become familiar with the patterns themselves.
Most of the patterns defined for the J2EE platform range between the design and architecture levels. The most common J2EE architecture is largely assumed—a 3-tier business system—as the context for these patterns. You may be able to apply individual patterns in different styles of architecture, but as a pattern language, the current J2EE patterns are squarely targeted at a 3-tier, Web-based business system. The 3 tiers are usually classified as the presentation or Web tier, the middle or business tier, and the integration or data tier.
As well as consisting of multiple tiers, the target architecture is roughly based on the Model-View-Controller (MVC) principle. MVC is a form of pattern that can be applied at several levels. At the GUI level, it splits the responsibilities for interacting with the user between a data model, a presentation-oriented view, and a controller to govern the interaction. At the architectural level, this translates into entity EJBs (and various other components) providing a data model, servlets and JSPs providing the view, and Session EJBs providing the controller or business logic. Separating concerns in this way delivers a lot of flexibility. An example of this is that the model and controller (the data and the business logic) can be combined with a variety of views to expose the same functionality to different clients. This is shown in Figure 18.1.
Given this context, and given that an overall application style is in place, why do you need more patterns? Well, the purpose of applying patterns within an n-tier application generally relates to the systemic qualities of the application. Systemic qualities, sometimes called non-functional requirements, refer to qualities such as maintainability, extensibility, scalability, availability, and so on. By applying the patterns outlined today, you should be able to improve at least one of these systemic qualities in your application, if not several. When the case study is examined later, the impact on systemic qualities of the patterns applied is also considered.
If you are designing an application from scratch, it will be second nature to think of applying patterns to the design process. However, many times you will be working within a pre-defined architecture or with an existing application. This does not mean that patterns no longer apply. It is quite possible to apply patterns to existing applications to improve them. It may be that the original design was not well thought out, or that it used the technologies in a naïve way (quite common when technologies are new). A pattern can be retro-fitted to part of the application to improve the systemic qualities of the application and to generally clean it up. This process is called refactoring, and is a key element in many software processes. As part of examining the case study, several potential refactorings will be considered.
The last thing that you need before examining the case study is knowledge of the patterns themselves.
Table 18.1 lists some common, generic patterns that are documented in the GoF book.
Table 18.2 lists patterns that have been identified around the presentation (or Web) tier of an n-tier J2EE application. The origin of each pattern is denoted using initials—SJC (Sun Java Center), BLU (Sun J2EE Blueprints), TSS (TheServerSide.com).
Table 18.3 lists patterns that have been identified around the business (or middle) tier of an n-tier J2EE application. The origin of each pattern is denoted using initials—SJC (Sun Java Center), BLU (Sun J2EE Blueprints), TSS (TheServerSide.com).
Table 18.4 lists patterns that have been identified around the integration (or data) tier of an n-tier J2EE application. The origin of each pattern is denoted using initials—SJC (Sun Java Center), BLU (Sun J2EE Blueprints), TSS (TheServerSide.com).
As noted previously, certain patterns occur within the J2EE environment itself, including the following:
The Proxy pattern (GoF) is used widely in J2EE. Examples include RMI stubs as client-side proxies and EJB objects as server-side proxies.
An EJB home interface acts as a Singleton (GoF) for the creation of EJB instances.
The servlet filters provided as part of J2EE 1.3 are a form of the Intercepting Filter pattern (SJC).
There are many other patterns that are applied within the Java and J2EE environments.
13.59.227.82