Welcome!

IBM Cloud Authors: Zakia Bouachraoui, Elizabeth White, Yeshim Deniz, Pat Romanski, Liz McMillan

Related Topics: IBM Cloud

IBM Cloud: Article

WebSphere Commerce Design Patterns - Part 2

Lending a uniform structure to design patterns

IBM's WebSphere Commerce product is a platform for developing and deploying value chain solutions from a consumer-centric online sales channel to a completely integrated, multi-tier 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 apps that adhere to the WebSphere Commerce framework. Furthermore, these patterns will help you customize the out-of-the-box capabilities of WebSphere Commerce.

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

In this two-part article, I 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 design patterns, making them easier to learn, compare, and use. In the first part, published in the June issue, I covered the controller command and task command. In this part, I'll cover Data Bean command and Display pattern.

Data Bean Command
INTENT: Avoid coupling a data object with the logic used to process and populate the data into the data object by moving this logic into a separate object. Modify the data fetching, processing, and population tasks independent of the actual data object.

MOTIVATION: WebSphere Commerce recommends using data beans (see the display pattern category) to display the data to the client. These data beans are data objects with properties, their getters and setters (essentially Java beans). The logic to fetch, process, and populate data must not be embedded in the data objects. Embedding this logic will strongly couple the implementation details with the data object. If your business needs change over time, this strong coupling will restrict you from modifying how your implementation fetches, processes, and populates data. If you have strong coupling and want to modify the implementation, you may have to rewrite your data object and change the client to this new data object.

Searching a product catalog is an important commerce feature. To display the results of your catalog search, you may use a data object that whose properties are defined for search criteria and search output. If your search implementation is coupled with the data object, you'll be forced to modify the data object or create a new data object when your search algorithm changes. This can be avoided by having the implementation in a separate object that can be varied dynamically with your business environment.

Suppose SearchDataBean is the data object that contains the search criteria and search output. SearchDataBean won't implement the search logic; instead the logic will be implemented by SearchDataBeanCmdImpl. By changing the implementation class, we can modify the search logic. SearchDataBean maintains a reference to the interface that will be implemented by the implementation class. DataBeanManager gets this interface reference from SearchDataBean and instantiates an appropriate implementation with the help of the CommandFactory. Furthermore, DataBeanManager will pass in a reference of the data bean to the implementation class so the implementer can get the input criteria and set the result data in the bean. See Figure 1

APPLICABILITY: Use this pattern when all of the following conditions apply:
a. You want to avoid coupling the data object and the algorithm used to fetch, process, and populate the data object.
b. You anticipate a change to the population business logic.
c. The data population business logic may vary with store type.

STRUCTURE:

See Figure 2

See Figure 3

PARTICIPANTS:
DataBeanCommand: A Java interface that declares the methods for the following tasks: to execute the logic that populates data beans, to set input properties that will be used by population logic, and to set/get the data bean reference. This interface is provided by the WebSphere Commerce Server.

DataBeanCommandImpl: An abstract class that provides the default implementation to the methods declared in DataBeanCommand. This interface is provided by the WebSphere Commerce Server.

ADataBeanCmd: A Java interface that declares additional methods required in fetch, process and populate operation. It also provides the name of the default implementation class that implements the methods that are defined by this interface and the business task logic. The CommandFactory instantiates the default class if it fails to find an appropriate implementation class in the command registry.

ADataBeanCmdImpl: Provides implementation for data fetching, processing, and population.

CommandFactory: Instantiates an appropriate implementation of ADataBeanCmd based on store type. The appropriate implementation class is defined in the command registry.

DataBean: The data object that's populated using the Data Bean Command pattern. This contains a reference to the command interface that's used to populate its properties.

DataBeanManager: The client class that executes the appropriate Data Bean Command implementation for a data bean.

Figure 3 illustrates the collaboration between participants in the Data Bean Command pattern.

CONSEQUENCES: The consequences of using the Data Bean Command pattern are as follows:
a. The Data Bean Command interface and implementation are first-class objects that can be manipulated and extended to change existing data fetching, processing, and population logic to provide new logic.
b. Data fetching, processing, and population logic can be changed without affecting the data objects.
c. Data objects must be aware of the (Data Bean Command) interface name whose implementation will be used to populate it. This interface name can be set explicitly by the client at runtime.
d. Each store type can have different fetching, processing, and population logic.

IMPLEMENTATION:
a. To create a new Data Bean Command in WebSphere Commerce you must create a new Java interface that extends DataBeanCommand and provides an implementation class for this extended Java interface. The implementation class must extend the default Data Bean Command implementation, DataBeanCommandImpl class.
b. The data population logic must be in the performExecute method. The caller (DataBeanManager) is programmed to the Data Bean Command interface. So all the input properties must be defined in the data bean or passed using setRequestProperties.
c. Always instantiate a Data Bean Command using the CommandFactory and call the execute method to execute the business process. Never call the implementation class's performExecute method directly.
d. A data bean instance must be explicitly passed into the Data Bean Command implementation class.
e. As a best practice, always use the populateDataBeanCommand method to populate the input data from the data bean to the Data Bean Command properties.
f. New population logic and extensions to existing population can be performed either by creating a new implementation class for the existing Data Bean Command interface or extending the existing Data Bean Command implementation class. When you make extensions, make sure you call the parent class's performExecute method.
g. You can modify the population logic by setting a different interface name in the data bean with setCommandInterfaceName.

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.


IoT & Smart Cities Stories
Moroccanoil®, the global leader in oil-infused beauty, is thrilled to announce the NEW Moroccanoil Color Depositing Masks, a collection of dual-benefit hair masks that deposit pure pigments while providing the treatment benefits of a deep conditioning mask. The collection consists of seven curated shades for commitment-free, beautifully-colored hair that looks and feels healthy.
The textured-hair category is inarguably the hottest in the haircare space today. This has been driven by the proliferation of founder brands started by curly and coily consumers and savvy consumers who increasingly want products specifically for their texture type. This trend is underscored by the latest insights from NaturallyCurly's 2018 TextureTrends report, released today. According to the 2018 TextureTrends Report, more than 80 percent of women with curly and coily hair say they purcha...
The textured-hair category is inarguably the hottest in the haircare space today. This has been driven by the proliferation of founder brands started by curly and coily consumers and savvy consumers who increasingly want products specifically for their texture type. This trend is underscored by the latest insights from NaturallyCurly's 2018 TextureTrends report, released today. According to the 2018 TextureTrends Report, more than 80 percent of women with curly and coily hair say they purcha...
We all love the many benefits of natural plant oils, used as a deap treatment before shampooing, at home or at the beach, but is there an all-in-one solution for everyday intensive nutrition and modern styling?I am passionate about the benefits of natural extracts with tried-and-tested results, which I have used to develop my own brand (lemon for its acid ph, wheat germ for its fortifying action…). I wanted a product which combined caring and styling effects, and which could be used after shampo...
The platform combines the strengths of Singtel's extensive, intelligent network capabilities with Microsoft's cloud expertise to create a unique solution that sets new standards for IoT applications," said Mr Diomedes Kastanis, Head of IoT at Singtel. "Our solution provides speed, transparency and flexibility, paving the way for a more pervasive use of IoT to accelerate enterprises' digitalisation efforts. AI-powered intelligent connectivity over Microsoft Azure will be the fastest connected pat...
There are many examples of disruption in consumer space – Uber disrupting the cab industry, Airbnb disrupting the hospitality industry and so on; but have you wondered who is disrupting support and operations? AISERA helps make businesses and customers successful by offering consumer-like user experience for support and operations. We have built the world’s first AI-driven IT / HR / Cloud / Customer Support and Operations solution.
Codete accelerates their clients growth through technological expertise and experience. Codite team works with organizations to meet the challenges that digitalization presents. Their clients include digital start-ups as well as established enterprises in the IT industry. To stay competitive in a highly innovative IT industry, strong R&D departments and bold spin-off initiatives is a must. Codete Data Science and Software Architects teams help corporate clients to stay up to date with the mod...
At CloudEXPO Silicon Valley, June 24-26, 2019, Digital Transformation (DX) is a major focus with expanded DevOpsSUMMIT and FinTechEXPO programs within the DXWorldEXPO agenda. Successful transformation requires a laser focus on being data-driven and on using all the tools available that enable transformation if they plan to survive over the long term. A total of 88% of Fortune 500 companies from a generation ago are now out of business. Only 12% still survive. Similar percentages are found throug...
Druva is the global leader in Cloud Data Protection and Management, delivering the industry's first data management-as-a-service solution that aggregates data from endpoints, servers and cloud applications and leverages the public cloud to offer a single pane of glass to enable data protection, governance and intelligence-dramatically increasing the availability and visibility of business critical information, while reducing the risk, cost and complexity of managing and protecting it. Druva's...
BMC has unmatched experience in IT management, supporting 92 of the Forbes Global 100, and earning recognition as an ITSM Gartner Magic Quadrant Leader for five years running. Our solutions offer speed, agility, and efficiency to tackle business challenges in the areas of service management, automation, operations, and the mainframe.