IBM Cloud Authors: Yeshim Deniz, Elizabeth White, Zakia Bouachraoui, 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.


See Figure 2

See Figure 3

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.

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
Atmosera delivers modern cloud services that maximize the advantages of cloud-based infrastructures. Offering private, hybrid, and public cloud solutions, Atmosera works closely with customers to engineer, deploy, and operate cloud architectures with advanced services that deliver strategic business outcomes. Atmosera's expertise simplifies the process of cloud transformation and our 20+ years of experience managing complex IT environments provides our customers with the confidence and trust tha...
Intel is an American multinational corporation and technology company headquartered in Santa Clara, California, in the Silicon Valley. It is the world's second largest and second highest valued semiconductor chip maker based on revenue after being overtaken by Samsung, and is the inventor of the x86 series of microprocessors, the processors found in most personal computers (PCs). Intel supplies processors for computer system manufacturers such as Apple, Lenovo, HP, and Dell. Intel also manufactu...
Darktrace is the world's leading AI company for cyber security. Created by mathematicians from the University of Cambridge, Darktrace's Enterprise Immune System is the first non-consumer application of machine learning to work at scale, across all network types, from physical, virtualized, and cloud, through to IoT and industrial control systems. Installed as a self-configuring cyber defense platform, Darktrace continuously learns what is ‘normal' for all devices and users, updating its understa...
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...
Apptio fuels digital business transformation. Technology leaders use Apptio's machine learning to analyze and plan their technology spend so they can invest in products that increase the speed of business and deliver innovation. With Apptio, they translate raw costs, utilization, and billing data into business-centric views that help their organization optimize spending, plan strategically, and drive digital strategy that funds growth of the business. Technology leaders can gather instant recomm...
OpsRamp is an enterprise IT operation platform provided by US-based OpsRamp, Inc. It provides SaaS services through support for increasingly complex cloud and hybrid computing environments from system operation to service management. The OpsRamp platform is a SaaS-based, multi-tenant solution that enables enterprise IT organizations and cloud service providers like JBS the flexibility and control they need to manage and monitor today's hybrid, multi-cloud infrastructure, applications, and wor...
The Master of Science in Artificial Intelligence (MSAI) provides a comprehensive framework of theory and practice in the emerging field of AI. The program delivers the foundational knowledge needed to explore both key contextual areas and complex technical applications of AI systems. Curriculum incorporates elements of data science, robotics, and machine learning-enabling you to pursue a holistic and interdisciplinary course of study while preparing for a position in AI research, operations, ...
After years of investments and acquisitions, CloudBlue was created with the goal of building the world's only hyperscale digital platform with an increasingly infinite ecosystem and proven go-to-market services. The result? An unmatched platform that helps customers streamline cloud operations, save time and money, and revolutionize their businesses overnight. Today, the platform operates in more than 45 countries and powers more than 200 of the world's largest cloud marketplaces, managing mo...
Trend Micro Incorporated, a global leader in cybersecurity solutions, helps to make the world safe for exchanging digital information. Our innovative solutions for consumers, businesses, and governments provide layered security for data centers, cloud workloads, networks, and endpoints. All our products work together to seamlessly share threat intelligence and provide a connected threat defense with centralized visibility and investigation, enabling better, faster protection. With more than 6,00...
Tapping into blockchain revolution early enough translates into a substantial business competitiveness advantage. Codete comprehensively develops custom, blockchain-based business solutions, founded on the most advanced cryptographic innovations, and striking a balance point between complexity of the technologies used in quickly-changing stack building, business impact, and cost-effectiveness. Codete researches and provides business consultancy in the field of single most thrilling innovative te...