Bhadri Madapusi

Subscribe to Bhadri Madapusi: eMailAlertsEmail Alerts
Get Bhadri Madapusi: homepageHomepage mobileMobile rssRSS facebookFacebook twitterTwitter linkedinLinkedIn


Related Topics: WebSphere

IBM WebSphere software products: Article

WebSphere Commerce Design Pattern

Writing applications that adhere to the WebSphere Commerce framework

The IBM WebSphere Commerce product is a platform for developing and deploying value-chain solutions from a consumer-centric online sales channel to a completely integrated, multitiered demand chain. A variety of design patterns were used to develop the WebSphere Commerce framework. By understanding and using these high-level design patterns, you can write WebSphere Commerce applications that adhere to the WebSphere Commerce framework. Furthermore, these patterns will help you to customize the out-of-the-box capabilities of WebSphere Commerce.

WebSphere Commerce design patterns fall into two main categories: 1) the command design patterns and 2) the display design patterns. In the first category are the Controller Command pattern, Task Command pattern, and Data Bean Command pattern. In the second category are the Smart Data Bean pattern and Command Data Bean pattern.

In this two-part article, I’ll discuss the design patterns in terms of the template described in the book Design Patterns – Elements of Reusable Object-Oriented Software by Erich Gamma et al. This template lends a uniform structure to the design patterns, making them easier to learn, compare, and use. In the first part, I’ll cover the controller command and task command. In the second part, to be published in the July issue (Volume 4, Issue 7), I’ll cover Data Bean command and Display pattern.

Controller Command
Intent: Decouple the implementation of the business process logic from the caller to provide the ability to have different implementations of business processes depending on the type of WebSphere Commerce store and to provide the ability to verify if the client is authorized to execute the process.

Motivation: In commerce applications, it’s necessary to have different implementations of a business process to accommodate various types of users and WebSphere Commerce stores. Furthermore, a business process can be configured by assembling a number of low-level business tasks.

For example, the logon process can vary depending on the user who tries to log on and the store to which the user logs on. As commerce application designers, we may not know how the logon business process and the user’s relationship with the store will change over time. So there’s a need to decouple the implementation of the business process from the caller.

The Controller Command pattern lets the caller make a request to an unspecified implementation of a business process by passing in the command name, store details, user details, and other properties required by the process. This pattern controls the business tasks (see Task Command pattern) that will be executed according to the properties that are passed into it. The key to this pattern is the Controller Command interface and the CommandFactory class. The Controller Command interface defines the interfaces that are to be implemented by the business process implementers. The CommandFactory class follows a typical Factory pattern to determine the appropriate business process implementation based on the command issued by the caller and the WebSphere Commerce store.

In the logon example, when a user issues the logon command, the CommandFactory class will instantiate the appropriate logon business process implementation based on the store. In Figure 1, the CommandFactory class instantiates StoreALogonCtrlCmdImpl or StoreBLogonCtrlCmdImpl depending on the store the user is trying to log on to. Once the right business process is instantiated, the controller (WebController) executes the process by calling the command’s execute method.



Applicability: Use this pattern when you want to do one of the following tasks:
  • Build your commerce system by assembling low-level business tasks (see Task Command Pattern) and your business process may change over time or new business tasks may be added.
  • Dynamically change the business process based on the type of WebSphere Commerce store.

Structure:


Participants:
ControllerCommand: A Java interface that declares the methods for the following tasks: to execute a business process, check for access control, set input properties that will be used by business tasks, and set the response properties that may be used by the client when a business process is completed. WebSphere Commerce Server provides this interface.

ControllerCmdImpl: Provides the default implementation for the methods declared in the ControllerCommand interface. WebSphere Commerce Server provides this class.

AControllerCommand: A Java interface that declares the additional methods required by a particular business process. It also provides the name of the default implementation class that implements the methods that are defined by this interface and the business process logic. CommandFactory instantiates the default class if it fails to find an appropriate implementation class in the command registry. For more details about the command registry, see the WebSphere Commerce Developers’ Guide.

AControllerCmdImpl: Provides the implementation for the methods declared in AControllerCommand and the implementation for the business process. Controls the business processes by calling appropriate business tasks based on data passed by the caller.

CommandFactory: Instantiates the appropriate implementation of the ATaskCommand based on store type. The appropriate implementation class is defined in the command registry. The CommandFactory class will instantiate the default implementation defined in the ATaskCommand if there’s no implementation class defined in the command registry.

WebController: Uses CommandFactory to create the appropriate implementation of AControllerCommand and triggers the implementation class to execute the business process.

Client: Requests the operation of a particular command.

More Stories By Bhadri Madapusi

Bhadri Madapusi is a software developer working in the IBM Toronto Lab's Electronic Commerce Division. He earned his MSc in information systems from BITS, India, and his MSc in computer science from Queens University, Canada. Bhadri's interests include software modeling, design patterns, and data management.

Comments (0)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.