SECTION 13 DESIGN PATTERNS

Section 13
13.1 Given a scenario description with a list of issues, select the design pattern (Value Objects, MVC, Data Access Object, or Business Delegate) that would best solve those issues.
13.2 Match design patterns with statements describing potential benefits that accrue from the use of the pattern, for any of the following patterns:
  • Value Objects
  • MVC
  • Data Access Object
  • Business Delegate

Section 13 Design Patterns

13.1 Given a scenario description with a list of issues, select the design pattern (Value Objects, MVC, Data Access Object, or Business Delegate) that would best solve those issues.

13.2 Match design patterns with statements describing potential benefits that accrue from the use of the pattern, for any of the following patterns:

  1. Value Objects
  2. MVC
  3. Data Access Object
  4. Business Delegate
Design Patterns
Pattern Description/Benefit/Issues
Value Objects
  • Reduce network traffic by acting as a caching proxy of a remote object.
  • Total load on the remote object's remote interface is decreased, because data represented by the Value Object are cached on the client by the Value Object instance. All accesses to the properties of the Value Objects are local, and so those accesses cause no remote method invocations.
  • Decreased latency can improve user response time.
  • Potential Liability - Stale data. Whenever a value object is backed by a volatile set of values (such as a stock's price and trading volume, for example) it should only be treated as a snapshot of those values.

It avoids unnecessary network round-trips by creating one-off transport objects to group together a set of related attributes needed by a client program,

MVC
  • Clarify design by separating data modeling issues from data display and user interaction.
  • Allow the same data to be viewed in multiple ways and by multiple users.
  • Improve extensibility by simplifying impact analysis.
  • Improve maintainability by encapsulating application functions behind well-known APIs, and decreasing code replication ("copy-paste-and-hack").
  • Enhance reusability by decoupling application functionality from presentation.
  • Make applications easier to distribute, since MVC boundaries are natural distribution interface points.
  • Can be used to partition deployment and enable incremental updates.
  • Facilitate testability by forcing clear designation of responsibilities and functional consistency.
  • Enhance flexibility, because data model, user interaction, and data display can be made "pluggable".

Cleanly separates the roles of data and presentation, allowing multiple types of client displays to work with the same business information.

Data Access Object
  • Abstract and encapsulate data access mechanisms
  • Greater deployment flexibility
  • Resource vendor independence
  • Resource implementation independence
  • Easier migration to CMP
  • Enhance extensibility
  • Increase complexity because of a level of indirection

Avoid unnecessary marshalling overhead by implementing dependent objects as lightweight, persistent classes instead of each as an Enterprise Bean.

Business Delegate
  • Reduce coupling between Web and Enterprise JavaBeans tiers, improve manageability.
  • Service exception translation
  • Simpler, uniform interface hiding the details.
  • Delegate may cache results - this may improve performance
  • Increase complexity because of a level of indirection

A business delegate decouples business components from the code that uses them. The pattern manages the complexity of distributed component lookup and exception handling, and may adapt the business component interface to a simpler interface for use by views.

The following patterns are not required for the certification test.
Application Service
  • Centralize and aggregate behavior to provide a uniform service layer.
  • Provide a central location to implement business logic that encapsulates Business Object and services.
  • Encapsulate this higher-level business logic in a separate component that uses the underlying Business Objects and services.
  • Include all the procedural business logic required to implement different services in your application and use Data Access Objects when necessary to deal with persistent data.
  • Reduce coupling among Business Objects.
Bimodal Data Access
  • Under certain conditions, allow designer to trade off data consistency for access efficiency. JDBC provides read-only, potentially dirty reads of lists of objects, bypassing the functionality, and the overhead, of Entity enterprise beans. At the same time, Entity enterprise beans can still be used for transactional access to enterprise data. Which mechanism to select depends on the requirements of the application operation
Composite Entity

Model a network of related business entities

Composite View

Separately manage layout and content of multiple composed views

Context Object
  • Encapsulate state in a protocol-independent way to be shared throughout an application.
  • Avoid using protocol-specific system information outside of its relevant context.
  • Object is shared with other parts of the application without coupling the application to a specific protocol.
  • Improve reusability, maintainability, extensibility, and testability
  • There is a modest performance hit, because state is transferred from one object to another.

For example, an HTTP request parameter exists for each field of an HTML form and a Context Object can store this data in a protocol-independent manner while facilitating its conversion and validation. Then other parts of the application simply access the information in the Context Object, without any knowledge of the HTTP protocol. Any changes in the protocol are handled by the Context Object, and no other parts of the application need to change.

Facade
  • Coordinate operations between multiple business objects in a workflow.
  • Provide a layer between clients and subsystems of a complex system.
  • Shield clients from subsystem components, making the subsystems easier to use.
  • Provide a restricted view of data and behavior of one or more business entities.
  • There are many categories of Facade patterns, like service facades, session entity facade, etc.

Session entity facade is an instance of the Facade pattern. It avoids inefficient remote client access of Entity Beans by wrapping them with a Session Bean and shares its applicability. Use the Session Facade pattern when you want to provide a simple interface to a complex subsystem of enterprise beans or when you want to reduce communication & dependencies between client objects and enterprise beans.

Factory method

Allow runtime instantiation of an appropriate subclass of a given interface or superclass based on externally-configurable information.

Fast-Lane Reader pattern

Avoid unnecessary overhead for read-only data by accessing JDBC API's directly. This allows an application to retrieve only the attributes that need to be displayed, instead of finding all of the attributes by primary key when only a few attributes are required by the client. Typically, implementations of this pattern sacrifice data consistency for performance, since queries performed at the raw JDBC level do not "see" pending changes made to business information represented by Enterprise Beans.

Improve read performance of tabular data.

Front Controller
  • Provide centralized dispatching of requests, e.g. via a controller servlet.
  • Enable centralized handling of security, navigation, and presentation formatting

Centralize view management (navigation, templating, security, etc.) for a Web application in a single object that handles incoming client requests.

Intercepting Filter

Pre- and post-process application requests

Page-by-Page Iterator Pattern

Avoid sending unnecessary data to the client by breaking a large collection into chunks for display.

Service Locator

Simplify client access to enterprise business services

Singleton
  • A class which can have at most one instance
  • For more info, click the left link.
Template Method
  • The key idea is that there is a basic algorithm we want to stay the same, but we want to let subclasses vary how they do the steps. The Template Method says to define the algorithm in the parent class, but implementations of the steps in the subclasses
Transfer Object

Transfer business data between tiers

Value Messenger

Keep client value object attributes in synch with the middle-tier business entity information that they represent in a bidirectional fashion.

Value List Handler

Efficiently iterate a virtual list

View Helper

Simplify access to model state and data access logic

More

More design patterns, focusing on GOF's 23

A good example of these design patterns can be found from Pet Store Demo project.

There are 200+ classes in this project. See the following list to study how the design pattern has been used:

Return to top