Results 1 to 1 of 1
  1. #1
    Java Exam is offline Member
    Join Date
    Dec 2011
    Posts
    64
    Rep Power
    0

    Default Tutorial:Review of Java Design Patterns for the Java Architect Exam

    In this article, we will look at applying java design patterns in Java EE. We will look at the most appropriate pattern for a given scenario in a JEE application. We will go into details of the benefits and drawbacks of each pattern. This is part of a larger series of articles to help you prepare for the java architect exam. The most recent article looked at common java architecture, “Tutorial:Review of EJB Application Architecture for the Java Architect Exam”.

    The Genesis of Java Design Patterns

    The idea of patterns and a pattern language was introduced by Christopher Alexander, a building architect as a means of applying certain solutions over and over again to the same or similar problems. He also combined these existing solutions to create new solutions to new problems. Later, Ward Cunningham and Kent Beck developed five patterns to use in interaction design and finally in 1994 Erich Gamma, Richard Helm, John Vlissides, and Ralph Johnson published the classic book Design Patterns: Elements of Reusable ObjectOriented Software, that documented patterns that has become a software industry standard.

    In 1999, with the introduction of Java 2 Enterprise Edition, Sun’s Java consulting practice in Sun Professional Services, realized that companies were not using the technology correctly and architecting solutions that were not scalable. It is within this context that John Crupi, Deepak Alur, and Danny Malks decided to document the appropriate patterns to successfully architect a JEE solution. This lead to the book, Core JEE Patterns: Best Practices and Design Strategies.

    We will describe how you can use patterns to help you create an architecture. Instead of using the pattern sat the object or class level, which is the custom, we will abstract them to a higher level. Initially we will focus on the Gang of Four (GoF) patterns, as described in the classic book, Design Patterns: Elements of Reusable Object-Oriented Software and then move on to the core JEE patterns, as described in the book, Core JEE Patterns, Crupi, et al. As an architect, we look for your knowledge of patterns to arrive at the following level:
    • Be able to describe each of the Gang of Four design patterns
    • Be able to describe each of the Core JEE patterns
    • Categorize a pattern as a Core JEE pattern or GoF design pattern based on the name
    • Understand the basics of applying patterns


    Gang of Four Patterns

    The GoF patterns are categorized into three categories, as follows:
    • Creational—Support the creation of objects
    • Structural—Deal with relationships between portions of your application
    • Behavioral—Influence how state and behavior flow through the system


    Creational Patterns

    Creational patterns are used to support the creation of objects in a system. They allow objects to be created in a system without needing to identify a specific class type in the code, thus avoiding the need to write large, complex code to instantiate an object. Creational patterns achieve this by leveraging the subclass of the class to create the objects. This may limit the type or number of objects that can be created within a system. The Creational patterns are Abstract Factory, Builder, Factory Method, Prototype, and Singleton.

    Abstract Factory Pattern

    The Abstract Factory pattern provides an interface for creating a family of related or dependent objects without specifying their concrete classes. Given a set of related abstract classes, the Abstract Factory pattern provides the means to create instances of these abstract classes from a matched set of concrete subclasses. The Abstract Factory pattern is shown in the figure below:.

    Tutorial:Review of Java Design Patterns for the Java Architect Exam-c6-abstractfactory.jpg
    Figure: Abstract Factory
    The Abstract Factory pattern uses an abstract class to determines the appropriate concrete class to instantiate in order to create a set of concrete products implementing a standard interface. The client only interacts with the product interfaces and the Abstract Factory class. The client never knows about the concrete construction classes provided in this pattern. This pattern is similar to the Factory Method pattern, except that it creates families of related objects.

    Benefits
    The benefits from using the Abstract Factory pattern are the following:
    • Isolates the concrete classes from client
    • Allows for exchanging product families easy
    • Promotes consistency among products by implementing a common interface


    When to Use
    The Abstract Factory pattern should be applied in the following situations:
    • When the system should be independent of how its products are created, composed, and represented.
    • When the system needs to be configured with one of multiple families of products such as for Microsoft Windows , Linux or Apple OSX classes.
    • When the family of related product objects are designed to be used together, and it is necessary to enforce this constraint. This is one of the key reasons for the existence of this pattern; otherwise, you could use a Factory Method.
    • When you want to provide a class library of products and only reveal their interfaces, not their implementations.


    Builder Pattern

    The Builder pattern is used to separate the construction of a complex object from its representation in order that the same construction process can be use to create different objects. The Builder pattern allows the client object to construct a complex object by providing its type and content. The client is shielded from all the details of the object’s construction. It simplifies the creation of complex objects by defining a class that is used to build instances of another class. The Builder pattern is often used to build product that are in accordance with the composite pattern. The figure illustrates the Builder pattern.

    Tutorial:Review of Java Design Patterns for the Java Architect Exam-c6-builderpattern.jpg
    Figure:Builder Pattern

    The Builder pattern allows you to create the complex objects one step at a time. Other patterns can build the object in a single step.

    Benefits
    The benefits from using the Builder pattern are the following:
    • It allows you to vary a product’s internal representation
    • It isolates the code for construction and representation
    • It gives you greater control over the construction process


    When to Use
    The Builder pattern should be applied in the following situations:
    • When the algorithm for creating a complex object should be independent of both the parts that make up the object and how these parts are assembled.
    • When the construction process must allow different representations of the constructed object.


    Factory Method Pattern

    The Factory Method pattern defines an interface for creating an object, but lets the subclasses determine which class to instantiate. The Factory Method allows a class to defer instantiation to subclasses. This is very is useful for constructing individual objects for a specific purpose without requiring the requestor to know the specific class being instantiated. This enables you to introduce new classes without the need to modify the code since the new class only implements the interface so it can be used by the client. The figure below shows the Factory Method pattern:

    Tutorial:Review of Java Design Patterns for the Java Architect Exam-c6-factorymethod.jpg
    Figure: Factory Method Pattern

    Benefits
    The benefits from using the Factory Method pattern are the following:
    • It eliminates the need to bind application classes into your code. The code relates only to the interface and you can work with any classes that implement the relevant interface.
    • It enables subclasses to provide an extended version of an object, since it is more flexible to create an object inside a class than to create an object directly in the client.


    When to Use
    The Factory Method pattern should be applied in the following situations:
    • When a class cannot anticipate the class of objects it must create.
    • When a class wants its subclasses to specify the objects it creates.
    • When classes delegate responsibility to one of several helper subclasses, and you want to localize the knowledge of which helper subclass is the delegate.


    Prototype Pattern

    The Prototype pattern is used by an object to create objects by cloning an existing object. It does this without knowing their exact class or the details of how to create them. Instead it specifies the kinds of objects to create using a prototypical instance and then creates new objects by copying this prototype. The Prototype pattern works by giving prototypical objects to an object and then initiates the creation of objects. The object that initiates the target object creation by asking the prototypical objects to make copies of themselves. The Prototype pattern makes creating objects dynamically easier by defining classes whose objects can duplicate themselves. The Prototype pattern is shown in the figure below:

    Tutorial:Review of Java Design Patterns for the Java Architect Exam-c6-prototype.jpg
    Figure:Prototype Pattern

    Benefits
    The benefits from using the Prototype pattern are the following:
    • It can add and remove products at run time
    • It specifies new objects by varying values
    • It specifies new objects by varying structure
    • It reduces subclasses
    • It configures an application with classes dynamically


    When to Use
    The Prototype pattern should be applied in the following situations:
    • When the classes to instantiate are specified at run time by dynamic loading for example.
    • When it’s necessary to avoid building a class hierarchy of factories paralleling the class hierarchy of products
    • When instances of a class can have one of only a few different combinations of state


    Singleton Pattern

    The Singleton pattern ensures that there is only one instance of a class and that provides a global point of access to the class. It ensures that all objects using an instance of this class use the same instance. The figure below shows the Singleton pattern:

    Tutorial:Review of Java Design Patterns for the Java Architect Exam-c6-singleton.jpg
    Figure:Singleton Pattern

    Benefits
    The benefits from using the Singleton pattern are the following:
    • It controlled access to sole instance
    • It reduces the name space
    • It permits refinement of operations and representation
    • It permits a variable number of instances More flexible than class operations


    When to Use
    The Singleton pattern should be applied in the following situation:
    • When there must be exactly one instance of a class.


    Structural Patterns

    Structural patterns deal with how classes and objects are composed into larger structures. Structural class patterns use inheritance in order to compose interfaces and implementations. They affect applications in a variety of ways. For example, the Adapter pattern enables two incompatible systems to communicate, and the Façade pattern enables one to present a simplified interface to a user without eliminating all the options available in the system.

    Structural patterns allow you to create systems without the need to rewrite or customize any code. This pattern allows for a system to have enhanced reusability and robust functionality. The structural patterns are Adapter, Bridge, Composite, Decorator, Façade, Flyweight, and Proxy.

    Adapter Pattern

    Adapter pattern acts as an intermediary between two classes, converting the interface of one class in order that it can be used with another. This pattern enables classes with incompatible interfaces to work together. The Adapter pattern allows classes with incompatible interfaces to work together by wrapping its own interface around that of an already existing class. It provides the functionality of an interface without having to know the class used to implement that interface. The figure below illustrates the Adapter pattern:

    Tutorial:Review of Java Design Patterns for the Java Architect Exam-c6-adapter.jpg
    Figure:Adapter Pattern

    Benefits
    The benefits from using the Adaptor pattern are the following:
    • It facilitates communication and interaction between two or more incompatible objects
    • It improves the reusability of legacy functionality


    When to Use
    The Adaptor pattern should be applied in the following situation:
    • When you want to use an existing class, and its interface does not match the interface you need.
    • When you want to create a reusable class that cooperates with unrelated or unforeseen classes—that is, classes that don’t necessarily have compatible interfaces.
    • When you want to use an object in an environment that expects an interface that is different from the object’s interface.
    • When interface translation among multiple sources must occur.


    Bridge Pattern

    The Bridge pattern divides a complex component into two separate but related inheritance hierarchies: the functional abstraction and the internal implementation. This makes it easier to change either aspect of the component so that the two can vary independently.

    The Bridge pattern is useful when there is a hierarchy of abstractions and a corresponding hierarchy of implementations. Rather than combining the abstractions and implementations into many distinct classes, the Bridge pattern implements the abstractions and implementations as independent classes allowing them to be combined dynamically. The figure below shows the Bridge pattern:

    Tutorial:Review of Java Design Patterns for the Java Architect Exam-c6-bridge.jpg
    Figure:Bridge Pattern

    Benefits
    The benefits from using the Bridge pattern are the following:
    • It enables you to separate the interface from the implementation
    • It improves extensibility
    • It hides implementation details from clients


    When to Use
    The Bridge pattern should be applied in the following situation:
    • When you want to avoid a permanent binding between an abstraction and its implementation.
    • When both the abstractions and their implementations should be extensible using subclasses.
    • When changes in the implementation of an abstraction should have no impact on clients; that is, you should not have to recompile their code.


    Composite Pattern

    The Composite pattern composes one-or-more similar objects such that they can be manipulated as one object. It enables you to create hierarchical tree structures of varying complexity, while also allowing every element in the structure to operate with a uniform interface. The Composite pattern combines objects into tree structures representing either the whole hierarchy or a part of the hierarchy allowing clients to treat individual objects and compositions of objects uniformly. The figure below illustrates the Composite pattern:

    Tutorial:Review of Java Design Patterns for the Java Architect Exam-c6-composite.jpg
    Figure:Composite Pattern

    Benefits
    The benefits from using the Composite pattern are the following:
    • Defines class hierarchies consisting of primitive objects and composite objects
    • Makes it easier to add new kinds of components
    • Provides flexibility of structure and a manageable interface


    When to Use
    The Composite pattern should be applied in the following situation:
    • When you want to represent the whole hierarchy or a part of the hierarchy of objects.
    • When you want clients to be able to ignore the difference between compositions of objects and individual objects.
    • When the structure can have any level of complexity and is dynamic.


    Decorator Pattern

    The Decorator pattern enables you to dynamically add or remove object functionality without changing the external appearance or function of the object. It changes the functionality of an object in a manner transparent to its clients by using an instance of a subclass of the original class to delegate operations to the original object. The Decorator pattern attaches additional responsibilities to an object dynamically to provide a flexible alternative to changing object functionality without using static inheritance. The figure below illustrates the Decorator pattern:

    Tutorial:Review of Java Design Patterns for the Java Architect Exam-c6-decorator.jpg
    Figure:Decorator Pattern

    Benefits
    The benefits from using the Decorator pattern are the following:
    • It has more flexibility than static inheritance
    • It avoids feature-laden classes high up in the hierarchy
    • It simplifies coding because you write a series of classes, each targeted at a specific part of the functionality, rather than coding all behavior into the object
    • It enhances the object’s extensibility because you make changes by coding new classes


    When to Use
    The Decorator pattern should be applied in the following situation:
    • When you want to add responsibilities to individual objects dynamically and transparently without affecting other objects.
    • When you want to add responsibilities to the object that you might want to change in the future.
    • When extension by static subclassing is impractical.


    Façade Pattern

    The Façade pattern provides a unified interface to a group of interfaces in a subsystem. The Façade pattern defines a higher-level interface that makes the subsystem easier to use since there is only one interface instead of many. This unified interface enables an object to access the subsystem using the interface to communicate with the subsystem. The figure below illustrates the Façade pattern:

    Tutorial:Review of Java Design Patterns for the Java Architect Exam-c6-facade.jpg
    Figure:Facade Pattern

    Benefits
    The benefits from using the Facade pattern are the following:
    • It provides a simple interface to a complex system without reducing the options provided by the system
    • It shields clients from subsystem components
    • It promotes weak coupling between the subsystem and its clients
    • It reduces coupling between subsystems if every subsystem uses its own Façade pattern and other parts of the system use the Façade pattern to communicate with the subsystem
    • It translates the client requests to the subsystems that can fulfill those requests


    When to Use
    The Facade pattern should be applied in the following situation:
    • You want to provide a simple interface to a complex subsystem.
    • There are many dependencies between clients and the implementation classes of an abstraction.
    • You want to layer your subsystems.


    Flyweight Pattern

    The Flyweight pattern reduces the number of low-level, detailed objects within a system by sharing objects. If instances of a class that contain the same information can be used interchangeably, the Flyweight pattern allows a program to avoid the expense of multiple instances that contain the same information by sharing one instance. The figure below illustrates the Flyweight pattern.

    Tutorial:Review of Java Design Patterns for the Java Architect Exam-c6-flyweight.jpg
    Figure:Flyweight Pattern

    Benefits
    The benefits from using the Flyweight pattern are the following:
    • It reduces in the number of objects to handle
    • It reduces in memory and on storage devices, if the objects are persisted


    When to Use
    The Flyweight pattern should be applied in the following situation:
    • When the application uses a large number of objects.
    • When storage costs are high because of the quantity of objects.
    • When the application doesn’t depend on object identity.


    Proxy Pattern

    The Proxy pattern provides a surrogate or placeholder object to control access to the original object. There are several types of implementations of the Proxy pattern, with the Remote proxy and Virtual proxy being the most common. The figure below illustrates the Proxy pattern.

    Tutorial:Review of Java Design Patterns for the Java Architect Exam-c6-proxy.jpg
    Figure:Proxy Pattern

    Benefits
    The benefits from using the Proxy pattern are the following:
    • It allows remote proxies to hide an object resides in a different address space.
    • It allows virtual proxies to perform optimizations, such as creating an object on demand.


    When to Use
    The Proxy pattern should be applied in the following situation:
    • When you need a more versatile or sophisticated reference to an object than a simple pointer.


    Behavioral Patterns

    Behavioral patterns focus on algorithms and the assignments of responsibilities between objects. These patterns shape the patterns of communication and characterize complex control flow through a system. By optimizing how state and behavior are transferred and modified, you can simplify, optimize, and increase the maintainability of an application.
    The Behavioral patterns are Chain of Responsibility, Command, Interpreter, Iterator, Mediator, Memento, Observer, State, Strategy, Template Method, and Visitor

    Chain of Responsibility Pattern

    The Chain of Responsibility pattern provides for loose coupling. It establishes a chain within a system, so that a message can either be handled at the level where it is first received, or be directed to an object that can handle it. The figure below illustrates the Chain of Responsibility pattern.

    Tutorial:Review of Java Design Patterns for the Java Architect Exam-c6-chainofresp.jpg
    Figure:Chain of Responsibility

    Benefits
    The benefits from using the Chain of Responsibility pattern are the following:
    • It reduces coupling
    • It increases flexibility in assigning responsibilities to objects
    • It allows a set of classes to behave as a whole, because events produced in one class can be sent on to other handler classes within the composite


    When to Use
    The Chain of Responsibility pattern should be applied in the following situation:
    • When more than one object can handle a request, and the handler isn’t known.
    • When you want to issue a request to one of several objects without specifying the receiver explicitly.
    • When the set of objects that can handle a request should be specified dynamically.


    Command Pattern

    The Command pattern encapsulates a request in an object, which enables you to store the command, pass the command to a method, and return the command like any other object. The figure below illustrates the Command pattern.

    Tutorial:Review of Java Design Patterns for the Java Architect Exam-c6-command.jpg
    Figure:Command Pattern

    Benefits
    • The benefits from using the Command pattern are the following:
    • It separates the object that invokes the operation from the one that knows how to perform it.
    • It’s easy to add new commands, because you don’t have to change existing classes.


    When to Use
    The Command pattern should be applied in the following situation:
    • When you want to parameterize objects by an action to perform.
    • When you specify, queue, and execute requests at different times.
    • When you must support undo, logging, or transactions.


    Interpreter Pattern

    The Interpreter pattern interprets a language to define a representation for its grammar along with an interpreter that uses the representation to interpret sentences in the language. The figure below illustrates the Interpreter pattern.

    Tutorial:Review of Java Design Patterns for the Java Architect Exam-c6-interpreter.jpg
    Figure:Interpreter Pattern

    Benefits
    The benefits from using the Interpreter pattern are the following:
    • It’s easy to change and extend the grammar.
    • The implementation of the grammar is easy.


    When to Use
    The Interpreter pattern should be applied in the following situation:
    • When the grammar of the language is simple.
    • When efficiency is not a critical concern.


    Iterator Pattern

    The Iterator pattern provides a consistent way to sequentially access items in a collection that is independent of and separate from the underlying collection. The figure below illustrates the Iterator pattern.

    Tutorial:Review of Java Design Patterns for the Java Architect Exam-c6-iterator.jpg
    Figure:Iterator Pattern

    Benefits
    The benefits from using the Iterator pattern are the following:
    • It supports variations in the traversal of a collection
    • It simplifies the interface of the collection


    When to Use
    The Iterator pattern should be applied in the following situation:
    • When accessing collection object’s contents without exposing its internal representation
    • When support of multiple traversals of objects in a collection
    • In order to provide a uniform interface for traversing different structures in a collection


    Mediator Pattern

    The Mediator pattern simplifies communication among objects in a system by introducing a single object that manages message distribution among other objects. The Mediator pattern promotes loose coupling by keeping objects from referring to each other explicitly, and it lets you vary their interaction independently. The figure below illustrates the Mediator pattern.

    Tutorial:Review of Java Design Patterns for the Java Architect Exam-c6-mediator.jpg
    Figure:Mediator Pattern

    Benefits
    The benefits from using the Mediator pattern are the following:
    • It decouples colleagues
    • It simplifies object protocols
    • It centralizes control
    • The individual components become simpler and easier to manage since they no longer need to directly pass messages to each other.
    • Components are more generic, because they no longer need to contain logic to deal with their communication with other components.


    When to Use
    The Mediator pattern should be applied in the following situation:
    • When a set of objects communicate in well-defined but complex ways.
    • When you want to customize a behavior that’s distributed between several objects without using subclasses.


    Memento Pattern

    The Memento pattern preserves a “snapshot” of an object’s state, so that the object can return to its original state without having to reveal its content to the rest of the world. The figure below illustrates the Memento pattern.

    Tutorial:Review of Java Design Patterns for the Java Architect Exam-c6-memento.jpg
    Figure:Memento Pattern

    Benefits
    The benefits from using the Memento pattern are the following:
    • It preserves encapsulation boundaries
    • It simplifies the originator


    When to Use
    The Memento pattern should be applied in the following situation:
    • When a snapshot of an object’s state must be saved so that it can be restored to that state later.
    • When using a direct interface to obtain the state would expose implementation details and break the object’s encapsulation.


    Observer Pattern

    The Observer pattern provides a way for a component to flexibly broadcast messages to interested receivers. It defines a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically. The figure below illustrates the Observer pattern.

    Tutorial:Review of Java Design Patterns for the Java Architect Exam-c6-observer.jpg
    Figure:Observer Pattern

    Benefits
    The benefits from using the Observor pattern are the following:
    • It abstracts coupling between subject and observer
    • It supports for broadcast communication


    When to Use
    The Observor pattern should be applied in the following situation:
    • When a change to one object requires changing the other object, and you don’t know how many objects need to change.
    • When an object should be able to notify other objects without making assumptions about the identity of those objects.


    State Pattern

    The State pattern allows an object to alter its behavior when its internal state changes. The object appears to change its class. The figure below illustrates the State pattern.

    Tutorial:Review of Java Design Patterns for the Java Architect Exam-c6-state.jpg
    Figure:State Pattern

    Benefits
    The benefits from using the State pattern are the following:
    • It localizes state-specific behavior and partitions behavior for different states
    • It makes state transitions explicit


    When to Use
    The State pattern should be applied in the following situation:
    • When an object’s behavior depends on its state, and it must change its behavior at run-time depending on that state.
    • When operations have large, multipart conditional statements that depend on the object’s state.


    Strategy Pattern

    The Strategy pattern defines a group of classes that represent a set of possible behaviors. These behaviors can then be used in an application to change its functionality. The figure below illustrates the Strategy pattern.

    Tutorial:Review of Java Design Patterns for the Java Architect Exam-c6-strategy.jpg
    Figure:Strategy Pattern

    Benefits
    The benefits from using the Strategy pattern are the following:
    • It provides an alternative to subclassing
    • It defines each behavior in its own class, which eliminates conditional statements
    • It’s easier to extend a model to incorporate new behaviors without recoding the application


    When to Use
    The Strategy pattern should be applied in the following situation:
    • When many related classes differ only in their behavior.
    • When you need different variants of an algorithm.
    • When an algorithm uses data unknown to clients.


    Template Method Pattern

    The Template Method pattern provides a method that allows subclasses to override parts of the method without rewriting it. Define the skeleton of an algorithm in an operation, deferring some steps to subclasses. The Template Method lets subclasses redefine certain steps of an algorithm without changing the algorithm’s structure. The figure below illustrates the Template Method pattern.

    Tutorial:Review of Java Design Patterns for the Java Architect Exam-c6-template.jpg
    Figure:Template Method

    Benefits
    The benefits from using the Template Method pattern are the following:
    • It is a fundamental technique for reusing code


    When to Use
    The Template Method pattern should be applied in the following situation:
    • When you want to implement the invariant parts of an algorithm once and use subclasses to implement the behavior that can vary.
    • When common behavior among subclasses should be factored and localized in a common class to avoid code duplication.


    Visitor Pattern

    The Visitor pattern provides a maintainable, easy way to represent an operation to be performed on the elements of an object structure. The Visitor pattern lets you define a new operation without changing the classes of the elements on which it operates. The figure below illustrates the Visitor pattern.

    Tutorial:Review of Java Design Patterns for the Java Architect Exam-c6-visitor.jpg
    Figure:Visitor Pattern

    Benefits
    The benefits from using the Visitor pattern are the following:
    • It makes adding new operations easy
    • It gathers related operations and separates unrelated ones


    When to Use
    The Visitor pattern should be applied in the following situation:
    • When an object structure contains many classes of objects with differing interfaces, and you want to perform operations on these objects that depend on their concrete classes.
    • When classes defining the object structure rarely change, but you often want to define new operations over the structure.


    Design Patterns Applied - Java EE Patterns

    The Core JEE patterns are widely used in organizations architecting Java EE systems. They were the result of the experiences and a knowledge base which had built up around the use of a Java EE platform. After the initial set of patterns were developed, a new set of patterns were added when Java EE was extended to cover web services. There are also a number of patterns that have become obsolete with new technologies introduced in Java EE 5.

    Presentation Tier

    Presentation tier patterns are used to organize components for improving re-use when presenting data to the client tier. It is not required to apply all of these patterns in the presentation tier as some of the patterns overlap in providing a similar solution to a common problem.

    Intercepting Filter

    The Intercepting Filter pattern provides the ability to manipulate a request prior to processing or to manipulate the response before sending the results of the request. The figure below illustrates the Intercepting Filter pattern.

    Tutorial:Review of Java Design Patterns for the Java Architect Exam-c6-interceptingfilter.jpg
    Figure:Intercepting Filter Patterns

    Benefits
    The benefits from using the Intercepting Filter pattern are the following:
    • It centralizes pre-processing of requests
    • It centralizes post-processing of responses


    When to Use
    The Intercepting Filter pattern should be applied in the following situation:
    • When you need to pre-process a request or response.
    • When you need to post-process a request or response.


    Context Object

    The Context Object pattern is used to encapsulate the specifics of protocol implementation to be shared. The figure below illustrates the Context Object pattern.

    Tutorial:Review of Java Design Patterns for the Java Architect Exam-c6-contextobject.jpg
    Figure:Context Object Pattern

    Benefits
    The benefits from using the Context Object pattern are the following:
    • It improves reusability and maintainability
    • It allows code to be portable across operating systems


    When to Use
    The Context Object pattern should be applied in the following situation:
    • When components need access to system information
    • In order to decouple application from underlining protocols and system interfaces


    Front Controller

    The Front Controller pattern creates central control logic for presentation request handling. The Front Controller is different from the Intercepting Filter in that the Front Controller is determining processing based on the request and an Intercepting Filter is modifying the request. The figure below illustrates the Front Controller pattern.

    Tutorial:Review of Java Design Patterns for the Java Architect Exam-c6-frontcontroller.jpg
    Figure:Front Controller Pattern

    Benefits
    The benefits from using the Front Controller pattern are the following:
    • It centralizes control logic
    • It improves reusability
    • It improves separation of concerns


    When to Use
    The Front Controller pattern should be applied in the following situation:
    • When you apply common logic to multiple requests
    • In order to separate processing logic from view


    Application Controller

    The Application Controller pattern is used to centralize retrieval and invocation of request-processing components, such as commands and views. The figure below illustrates the Application Controller.

    Tutorial:Review of Java Design Patterns for the Java Architect Exam-c6-appcontroller.jpg
    Figure:Application Controller Pattern

    Benefits
    The benefits from using the Application Controller pattern are the following:
    • It improves extensibility
    • It improves separation of concerns


    When to Use
    The Application Controller pattern should be applied in the following situation:
    In order to apply common control logic
    When you have centralized view management

    View Helper

    The View Helper pattern separates the processing logic from the view. The figure below illustrates the View Helper pattern.

    Tutorial:Review of Java Design Patterns for the Java Architect Exam-c6-viewhelper.jpg
    Figure:View Helper Pattern

    Benefits
    The benefits from using the View Helper pattern are the following:
    • It separates logic from the view


    When to Use
    The View Helper pattern should be applied in the following situation:
    • In order to encapsulate view-processing logic


    Composite View

    The Composite View pattern combines simple views into a more complex view without handling the content or layout. The figure below illustrates the Composite View pattern.

    Tutorial:Review of Java Design Patterns for the Java Architect Exam-c6-compositeview.jpg
    Figure:Composite View Pattern

    Benefits
    The benefits from using the Composite View pattern are the following:
    • It code duplication is reduced because you can create common headers, footers, and other components.
    • It views can be changed based on access authorization.


    When to Use
    The Composite View pattern should be applied in the following situation:
    • When you want common view components.
    • When you view component changes based on authorization.


    Dispatcher View

    The Dispatcher View pattern handles the request and generates a response while managing limited business processing. The figure below illustrates the Dispatcher View pattern.

    Tutorial:Review of Java Design Patterns for the Java Architect Exam-c6-dispatcherview.jpg
    Figure:Dispatcher View Pattern

    Benefits
    The benefits from using the Dispatcher View pattern are the following:
    • It separates processing logic from view
    • It improves reusability


    When to Use
    The Dispatcher View pattern should be applied in the following situation:
    • When you have static views.
    • When you have limited business processing.


    Service to Worker

    The Service to Worker pattern performs request handling and invokes business logic before control is passed to the view. The figure below illustrates the Service to Worker pattern.

    Tutorial:Review of Java Design Patterns for the Java Architect Exam-c6-servicetoworker.jpg
    Figure:Service to Worker Pattern

    Benefits
    The benefits from using the Service to Worker pattern are the following:
    • It improves separation of concerns


    When to Use
    The Service to Worker pattern should be applied in the following situation:
    • In order to centralize business logic for requests


    Business Tier

    Business tier patterns create a loose coupling among the business logic, presentation, and resources.

    Business Delegate

    The Business Delegate pattern hides the complexity of remote communication with business components from the client. The figure below illustrates the Business Delegate pattern.

    Tutorial:Review of Java Design Patterns for the Java Architect Exam-c6-businessdelegate.jpg
    Figure:Business Delegate Pattern

    Benefits
    The benefits from using the Business Delegate pattern are the following:
    • It minimizes coupling of clients to business services
    • It hides remoteness
    • It improves performance


    When to Use
    The Business Delegate pattern should be applied in the following situation:
    • When you want to encapsulate access to business services from multiple client types
    • In order to translate exceptions into application exceptions Hide details of service creation


    Service Locator

    The Service Locator pattern uses a consistent approach to locating business components regardless of the type of components. The figure below illustrates the Service Locator pattern.

    Tutorial:Review of Java Design Patterns for the Java Architect Exam-c6-servicelocator.jpg
    Figure:Service Locator Pattern

    Benefits
    The benefits from using the Service Locator pattern are the following:
    • It standardizes the approach to retrieving business components


    When to Use
    The Service Locator pattern should be applied in the following situation:
    • When you have many different business services that are located in different ways.


    Session Façade

    The Session Façade pattern provides a coarse-grained service of business components to remote clients. This is the same as a Façade pattern, but just provides an interface to a service instead of code. The figure below illustrates the Session Façade pattern.

    Tutorial:Review of Java Design Patterns for the Java Architect Exam-c6-sessionfacade.jpg
    Figure:Session Facade Pattern

    Benefits
    The benefits from using the Session Facade pattern are the following:
    • It reduces the number of calls to the business component from the client
    • It reduces coupling between the tiers
    • It improves performance by reducing fine-grained calls from client
    • It provides a cleaner API to the client


    When to Use
    The Session Facade pattern should be applied in the following situation:
    • When you have a series of calls to make to business components from the client.


    Application Service

    The Application Service pattern centralizes and aggregates business components. An application service could be thought of as a helper to the Session Façade that takes care of all the business logic and workflow. The figure below illustrates the Application Service pattern.

    Tutorial:Review of Java Design Patterns for the Java Architect Exam-c5-appservice.jpg
    Figure:Application Service Pattern

    Benefits
    The benefits from using the Application Service pattern are the following:
    • It centralizes and improves reusability of business logic
    • It simplifies the Session Façade by eliminating the business logic


    When to Use
    The Application Service pattern should be applied in the following situation:
    • In order to start to see duplicated business logic in the Session Façade


    Business Object

    The Business Object pattern separates business data from logic. The figure below illustrates the Business Object pattern.

    Tutorial:Review of Java Design Patterns for the Java Architect Exam-c6-businessobject.jpg
    Figure:Business Object Pattern

    Benefits
    The benefits from using the Business Object pattern are the following:
    • It separates persistence from business logic.


    When to Use
    The Business Object pattern should be applied in the following situation:
    • When you want to increase reusability of business logic.


    Composite Entity

    The Composite Entity pattern aggregates business entities into a coarsegrained entity. The figure below illustrates the Composite Entity pattern.

    Benefits
    The following lists the benefits of using the Composite Entity pattern:
    • It increases maintainability
    • It improves network performance


    Tutorial:Review of Java Design Patterns for the Java Architect Exam-c6-compositeentity.jpg
    Figure:Composite Entity Patterns

    When to Use
    The Composite Entity pattern should be applied in the following situation:
    • In order to avoid remote entity beans
    • In order to leverage bean managed persistence (BMP) with custom persistence implementation
    • In order to encapsulate POJO business objects


    Transfer Object

    The Transfer Object pattern uses an object to carry data across tiers. The figure below illustrates the Transfer Object pattern.

    Tutorial:Review of Java Design Patterns for the Java Architect Exam-c6-transferobject.jpg
    Figure:Transfer Object Pattern

    Benefits
    The benefits from using the Transfer Object pattern are the following:
    • It reduces network traffic
    • It reduces code duplication



    When to Use
    The Transfer Object pattern should be applied in the following situation:
    • You need to send objects between tiers.


    Transfer Object Assembler

    The Transfer Object Assembler pattern builds a composite transfer object and returns to the client. The figure below illustrates the Transfer Object Assembler.

    Tutorial:Review of Java Design Patterns for the Java Architect Exam-c6-transferobjectassembler.jpg
    Figure:Transfer Object Assembler Pattern

    Benefits
    The benefits from using the Transfer Object Assembler pattern are the following:
    • It improves network performance


    When to Use
    The Transfer Object Assembler pattern should be applied in the following situation:
    • When you have several transfer objects that are sent between tiers.


    Value List Handler

    The Value List Handler pattern caches results and allows the client to traverse and select from the results. The figure below illustrates the Value List Handler pattern.

    Tutorial:Review of Java Design Patterns for the Java Architect Exam-c6-valuelisthandler.jpg
    Figure:Value List Handler Pattern

    Benefits
    The benefits from using the Value List Handler pattern are the following:
    • It caches search results
    • It improves network performance
    • It improves separation of concerns


    When to Use
    The Value List Handler pattern should be applied in the following situation:
    • When one desires to iterate through a set of objects.
    • When one implements read-only lists without transactions.


    Integration Tier

    Integration tier patterns serve to isolate the core business logic of a system from all external legacy or new systems including various data stores.

    Data Access Object

    The Data Access Object pattern encapsulates access to a persistent store by managing the connection with the data store. The figure below illustrates the Data Access Object pattern.

    Tutorial:Review of Java Design Patterns for the Java Architect Exam-c6-dataaccessobject.jpg
    Figure:Data Access Object Patterns

    Benefits
    The benefits from using the Data Access Object pattern are the following:
    • It reduces code complexity in client
    • It improves code reuse
    • It provides easier migration to new data store


    When to Use
    The Data Access Object pattern should be applied in the following situation:
    • In order to decouple data access from the business logic
    • In order to provide all data access from a separate layer


    Service Activator

    The Service Activator pattern handles asynchronous requests to business components. The figure below illustrates the Service Activator pattern.

    Tutorial:Review of Java Design Patterns for the Java Architect Exam-c6-serviceactivator.jpg
    Figure:Service Activator

    Benefits
    The benefits from using the Service Activator pattern are the following:
    • It allows the client to continue processing
    • It integrates JMS into application


    When to Use
    The Service Activator pattern should be applied in the following situation:
    • When you need to invoke a business service in an asynchronous manner.


    Domain Store

    The Domain Store pattern separates the persistence of an object from the object model. This pattern really became relevant with the advent of object relational model frameworks and products. You would use the domain store and data access object at the same time. The figure below illustrates the Domain Store pattern.

    Tutorial:Review of Java Design Patterns for the Java Architect Exam-c6-domainstore.jpg
    Figure:Domain Store Pattern

    Benefits
    The benefits from using the Domain Store pattern are the following:
    • It decouples business logic from persistence logic


    When to Use
    The Domain Store pattern should be applied in the following situation:
    • When you do not want to use entity beans.
    • When the object model uses are complex.


    Web Service Broker

    The Web Service Broker pattern exposes and brokers services using XML and web protocols. The figure below illustrates the Web Service Broker pattern.

    Tutorial:Review of Java Design Patterns for the Java Architect Exam-c6-webservicebroker.jpg
    Figure:Web Service Broker Pattern

    Benefits
    The benefits from using the Web Service Broker pattern are the following:
    • It exposes existing services to web


    When to Use
    The Web Service Broker pattern should be applied in the following situation:
    • Need to expose services as web services


    Summary

    When applying the patterns from the catalog we have presented, developers need to consider a wide array of design issues affecting numerous aspects of the system. This includes security, data integrity, manageability, and scalability.

    The majority of these design issues could also be captured in pattern form, but we were focused on a lower level of abstraction than what we be needed to address those issues. it is on top of these abstractions that you will formulate the design patterns necessary to address these issues. Overall, the purpose here is to help you avoid making problematic choices that could lead to costly and difficult problems to address. That is the purpose of java design patterns. To make this process easier. We are now on to the last two articles in order to prepare you for the architecture exam. The next article will be on security. See you then.
    Attached Thumbnails Attached Thumbnails Tutorial:Review of Java Design Patterns for the Java Architect Exam-c6-state.jpg   Tutorial:Review of Java Design Patterns for the Java Architect Exam-c5-appservice.jpg  

Similar Threads

  1. Replies: 0
    Last Post: 04-05-2012, 04:49 PM
  2. Replies: 0
    Last Post: 04-05-2012, 04:19 PM
  3. Replies: 0
    Last Post: 03-30-2012, 12:28 PM
  4. Replies: 0
    Last Post: 03-26-2012, 01:11 PM
  5. Replies: 0
    Last Post: 03-24-2012, 04:22 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •