Design Patterns: Exam Objectives
Design Patterns: Exam Objectives
Exam Objectives
Demonstrate knowledge of Java EE design patterns including: Service Starter, Singleton, Bean Locator, Resource Binder, Dependency Injection, Payload Extractor, Context Holder, and Thread Tracker. Select an appropriate pattern for a given application challenge from the following: Facade, Strategy, Observer, Composite, and Abstract Factory. Identify a design pattern, using a description of its features, from the following: Facade, Strategy, Observer, Composite, and Abstract Factory. Identify the use of the law of leaky abstractions or a specific anti-pattern in a given scenario. Select the appropriate pattern for a given scenario from the following Web Services patterns: Web Service Cache, Web Service Broker, Asynchronous Interactions, and JMS bridge.
bean-name ># < fully-qualified-interface-name >. The app-name and fully-qualified-interfacename are optional. Neither the use of the JNDI API itself nor the construction of the JNDI names is convenient. The encapsulation of both in a utility class (BeanLocator) makes the lookup not only more convenient, but it also reduces potential errors and decouples the application from the JNDI details. Forces Domain and infrastructural JNDI code needs to be separated. The global JNDI name should be constructed conveniently by minimizing potential errors. BeanLocator should be responsible for the global JNDI name construction, as well as for performing the actual JNDI lookup with eventual casting to the expected type. Resource Binder Bind a custom resource into JNDI using a @Singleton with @Startup and the JNDI API (Context.(re)bind()). Note that application servers proprietary JNDI implimentation may enforce some restrictions on the resource object (such as serializability). Dependency Injection Extender pattern The problem: You need to use some kind of Dependency Injection (DI for short) to provision some System Under Test (SUT for short) in tests you are writing, but can not or do not want to use a DI framework to do so. Of course, the simplest form of DI is simply passing things to a constructor. But you probably do not want to code every class to be handed every dependency at construction. And you definitely do not want to expose the private implementation through some unnecessary interface. The solution: Dependency Injection by Extension pattern. How it works: We need to provide DI helper s as protected methods in our SUT and subclass it from within test case as script-level class, to expose the DI helpers as public and/or use constructor to do some of the DI work allowing us to inject mocked dependencies for our test.
The extraction of the payload requires you to check the message type, cast it, extract the payload, potentially cast it again (for example, casting the ObjectMessage payload from Serializable to something more meaningful), and catch and properly handle checked exceptions. These tasks are repetitive, verbose, and error-prone. Especially hard to implement is proper handling of wrong message types. All destination instances are identical-they are distinguished only by their names, not by the message type. Nothing prevents other producers from sending messages with unexpected types. Such unexpected messages can cause ClassCastExceptions, which leads to the rollback of the current transaction. As a result, the message would be delivered again. The number of attempts depends on the message providers configuration. Ignoring unwanted messages is not a good strategy either; the messages will disappear from the destination and with them will disappear the chance to find the actual configuration error. Syntactically incorrect messages or messages with wrong types are often called poisoned messages. Poisoned messages have to be handled properly. At the very least, they have to be redirected into a dedicated dead-letter queue. The type checking and error handling is reusable and has to be factored out from the actual processing logic. PayloadExtractor should streamline the MessageDrivenBean implementation. Solution An interceptor is an obvious candidate for the realization of cross-cutting concerns such as errorhandling and payload extraction. The method MessageDrivenBeans# onMessage can be entirely wrapped by an interceptor.
Dispatcher View (View management) Combine a controller and dispatcher with views and helpers to handle client requests and prepare a dynamic presentation as the response. Controllers do not delegate content retrieval to helpers, because these activities are deferred to the time of view processing. A dispatcher is responsible for view management and navigation and can be encapsulated either within a controller, a view, or a separate component. Java EE Design Patterns Service to Worker (View management and navigation) Combine a controller and dispatcher with views and helpers to handle client requests and prepare a dynamic presentation as the response. Controllers delegate content retrieval to helpers, which manage the population of the intermediate model for the view. A dispatcher is responsible for view management and navigation and can be encapsulated either within a controller or a separate component. Java EE Design Patterns
Business Delegate (Business Service Adapter) Use a Business Delegate to reduce coupling between presentation-tier clients and business services. The Business Delegate hides the underlying implementation details of the business service, such as lookup and access details of the DB architecture. Session Facade (Hides business objects workflow layer) Use a session bean as a facade to encapsulate the complexity of interactions between the business objects participating in a workflow. The Session Facade manages the business objects, and provides a uniform coarse-grained service access layer to clients.
Service Locator (Caches JNDI objects) Use a Service Locator object to abstract all JNDI usage and to hide the complexities of initial context creation, EJB home object lookup, and EJB object re-creation. Multiple clients can reuse the Service Locator object to reduce code complexity, provide a single point of control, and improve performance by providing a caching facility. Value List Handler (Search Result service to the clients requirements) Use a Value List Handler to control the search, cache the results, and provide the results to the client in a result set whose size and traversal meets the client's requirements. Composite Entity (Manages database table relationships) Use Composite Entity to model, represent, and manage a set of interrelated persistent objects rather than representing them as individual fine-grained entity beans. A Composite Entity bean represents a graph of objects.
Front Controller (Central point of access for all requests) Use a controller as the initial point of contact for handling a request. The controller manages the handling of the request, including invoking security services such as authentication and authorization, delegating business processing, managing the choice of an appropriate view, handling errors, and managing the selection of content creation strategies.
Transfer Object (Used to transfer the enterprise data in between the tiers) Use a Transfer Object to encapsulate the business data. A single method call is used to send and retrieve the Transfer Object. When the client requests the enterprise bean for the business data, the enterprise bean can construct the Transfer Object, populate it with its attribute values, and pass it by value to the client. Service Activator (Asynchronous Processor) Use a Service Activator to receive asynchronous client requests and messages. On receiving a message, the Service Activator locates and invokes the necessary business methods on the business service components to fulfill the request asynchronously. Data Access Object (Decouple SQL Logic from business components) Use a Data Access Object (DAD) to abstract and encapsulate all access to the data source. The 0.4.0 manages the connection with the data source to obtain and store data.
Web Service Broker A Web Service Broker to expose and broker one or more services using XML and web protocols. Strategies Custom XML Messaging Strategy Java Binder Strategy Web Service Cache Despite advancements in network and processor speeds, performance remains a key concern among application developers. So whether you are writing an XML Web service, pushing image bitmaps to a video card, or even engineering that next great processing chip, you will invariably want to consider utilizing a universal mechanism for improving performance: a cache. Application Caching HTTP Caching Performing application caching on the server, caching responses on the client, or simply designing options in your XML Web service so that smart clients can offload some of the fundamental processing work from your server.