DP FR
DP FR
SWE2019
SLOT: A2
Review - 3
Group Members:
In a rapidly growing coffee shop, both customers and staff struggle with the high
demand for customizable orders, especially during peak hours. Customers want a wide
range of coffee flavors, varying sugar levels, and several add-ons, which makes placing
individual orders repetitive and inefficient. This leads to longer wait times, customer
dissatisfaction, and a high likelihood of errors in the order processing system.
To solve these issues, the coffee shop has implemented a software system that
integrates the Factory, Builder, and Command design patterns. This combination
provides a streamlined process for handling large and customized coffee orders, reducing
the manual work involved in preparing each order while ensuring accuracy and
consistency.
By utilizing the Factory Design Pattern, the system can dynamically generate
different types of coffee based on user input, reducing the need for repeated manual
selection of options. The Builder Pattern simplifies the complex order creation process
by allowing customers to easily specify various attributes (like size, flavor, sugar level,
and add-ons) in a step-by-step manner. Finally, the Command Pattern ensures that
customer requests are handled as discrete actions, allowing for better management of
queued orders, support for undo operations, and easier tracking of order status.
This integration enhances both the customer experience and the efficiency of the
workers, resulting in faster service, reduced errors, and higher customer satisfaction.
.
2. MOTIVATION:
In modern software development, flexibility, scalability, and maintainability are key to building
robust systems that can handle complex tasks and evolve with user needs. In the context of a coffee shop
with high customer volume and a wide range of order customizations, creating a system that can
efficiently handle these varying requirements is a significant challenge.
To achieve this, the software must manage object creation and order processing in a way that is
both abstract enough to support future changes and specific enough to ensure smooth, accurate execution
of orders. Three design patterns—Factory, Builder, and Command—work together to solve this
problem by addressing different aspects of the order creation and management process.
The Factory Pattern provides a clean, scalable way to instantiate the different types of
coffee, such as lattes, espressos, or cappuccinos, without requiring changes to the core system.
By delegating the instantiation to a factory, the system remains flexible, allowing new coffee
types or flavors to be added with minimal effort.
The Command Pattern enhances the system further by encapsulating each customer
action (placing an order, modifying it, or canceling it) into discrete command objects. This allows
the system to queue and execute actions more efficiently, enabling features like undoing orders,
tracking status, or modifying requests on the fly. It also ensures that multiple actions can be
managed simultaneously without disrupting service.
By combining these three design patterns, the coffee shop’s software becomes a powerful tool
that streamlines order processing while maintaining flexibility. The system can easily scale to
accommodate new customization options and features, handle large volumes of orders without delays,
and offer better control and visibility to both customers and staff.
This approach not only adheres to object-oriented principles like encapsulation and separation of
concerns but also promotes code reuse and ease of extension. As a result, the coffee shop can deliver
high-quality service, even as the complexity and volume of orders continue to grow, ensuring customer
satisfaction and operational efficiency.
3. DOMAIN DESCRIPTION:
The domain of the Online Coffee Ordering System encompasses a comprehensive set of
functionalities required to manage the operations of an online platform for ordering coffee and related
products. This system is crucial for both customers, who seek convenience in ordering their favorite
beverages, and the business, which aims to provide a seamless and efficient service.
Product Management:
1. Cataloging: The system must support the cataloging of coffee products and other related
items, including the addition, updating, and deletion of entries. Each product must be
associated with metadata such as name, type, size, price, and availability.
2. Customization: Customers should be able to customize their orders (e.g., type of coffee, milk
options, sugar levels) to match their preferences.
3. Inventory Management: The system needs to track the inventory of coffee products and
ingredients, ensuring real-time updates on availability and notifying staff when items need to
be restocked.
User Management:
1. User Registration: The system must allow new users to register, creating accounts with
relevant details such as contact information, payment preferences, and order history.
2. Authentication and Access Control: Users must be authenticated to access certain features
of the system, with role-based access (e.g., customers vs. administrators).
3. Loyalty Programs: The system should support the management of loyalty programs,
allowing customers to earn and redeem points based on their purchases.
1. Order Placement: The system must enable users to easily place orders for coffee and related
products, providing options for delivery or pickup.
2. Payment Processing: The system should handle secure payment processing, supporting
multiple payment methods such as credit/debit cards, digital wallets, and cash on delivery.
3. Order Tracking: Customers should be able to track the status of their orders in real time,
from preparation to delivery.
1. Search Functionality: The system must provide robust search capabilities, allowing users to
search for products by name, type, or other criteria. The search should be efficient and return
accurate results.
2. Filtering and Sorting: Users should be able to filter search results by various parameters,
such as price, type, or popularity, and sort them according to relevance or customer ratings.
‘
Notification and Alerts:
1. Order Confirmation: The system should automatically notify users when their order is
confirmed, including details of the estimated delivery or pickup time.
2. Order Status Updates: Customers should receive notifications as their order progresses, such
as when it is being prepared, out for delivery, or ready for pickup.
3. Promotional Alerts: Users should be informed about ongoing promotions, discounts, and
special offers through the system.
1. Sales Reports: The system should generate reports on sales performance, including the most
popular products, peak ordering times, and customer demographics.
2. Inventory Reports: Administrators should be able to generate reports on inventory levels,
including items that need to be reordered or restocked.
3. Customer Insights: The system should provide analytics on customer behavior, preferences,
and feedback to inform business decisions.
1. Third-Party Integrations: The system should be able to integrate with external platforms,
such as delivery services, payment gateways, or customer relationship management (CRM)
systems.
2. Modularity: The Online Coffee Ordering System should be designed to easily incorporate
additional modules, such as catering services, subscription plans, or gift card management.
1. Data Protection: The system must ensure the security and privacy of user data, including
compliance with relevant data protection regulations.
2. Backup and Recovery: The system should have mechanisms for data backup and recovery to
prevent data loss in case of system failure.
4. DESIGN PATTERNS INVOLVEMENT:
The Factory Design Pattern is used to dynamically create different coffee types based on user
preferences. For example, when a customer selects a coffee type like Espresso, Cappuccino, or Latte, the
Factory Pattern ensures the correct object is instantiated without exposing the creation logic to the user.
This allows the system to manage a wide variety of predefined coffee types seamlessly, reducing the
repetitive manual selection process for staff and ensuring consistency in coffee preparation. By
standardizing the creation of coffee objects, the pattern simplifies the backend logic and accelerates
order processing.
The Builder Design Pattern is employed to manage the complexity of customizable coffee
orders. It allows customers to specify details like size, flavor, sugar level, and add-ons step by step. This
structured approach ensures all customization options are captured systematically, preventing errors that
may arise from missing or mismatched details. By breaking down the customization process into
manageable steps, the Builder Pattern provides a user-friendly interface for customers and reduces the
cognitive load on staff while maintaining flexibility in handling complex orders.
The Command Design Pattern organizes each customer request as a discrete command,
enabling better order management. When a customer places an order, the system records it as a
command object, which can be executed, queued, or even undone if changes are needed (e.g., removing
an add-on). This pattern improves the efficiency of handling queued orders, ensuring that each command
is processed sequentially. Additionally, it provides greater transparency by tracking the status of each
order, enabling staff to monitor progress and make adjustments easily.
The Singleton Design Pattern ensures that only one instance of the order-processing system
operates at any given time. This centralized control prevents conflicts and ensures that orders are handled
sequentially, especially during peak hours. By maintaining a single point of access to the system, the
Singleton Pattern eliminates the risk of duplicate or conflicting processes, enhancing reliability. It also
ensures scalability by providing a consistent interface for managing orders, ultimately improving both
customer experience and staff efficiency.
The Factory pattern is proposed to enhance the design of the Online Coffee Ordering System
by providing a flexible and scalable approach to object creation. This pattern allows for the creation
of objects without specifying the exact class of object that will be created, thereby promoting loose
coupling and enhancing the system's extensibility.
In the context of the Online Coffee Ordering System, the Factory pattern can be applied to
manage the creation of various product objects, such as different types of coffee, add-ons, and
customizations. Instead of instantiating these objects directly within the system's code, a dedicated
factory class is responsible for creating the appropriate product objects based on user input or system
requirements.
For instance, when a customer places an order, the system can use a factory to generate the
specific coffee type and any add-ons (like extra sugar, milk, or flavorings) based on the customer's
selections. This approach allows for easy addition of new coffee types or customization options in the
future, without the need to alter existing code significantly.
By applying the Factory pattern, the Online Coffee Ordering System achieves several key
benefits:
Encapsulation of Object Creation: The pattern encapsulates the instantiation logic, reducing
dependencies and making the code easier to maintain and extend.
Scalability: New products or customizations can be added to the system with minimal
changes to the overall codebase, supporting the system’s growth over time.
Flexibility: Different product variations can be created dynamically based on user preferences
or business logic, enabling a highly customizable user experience.
Moreover, the Factory pattern aligns with the system's objectives of enhancing modularity,
maintainability, and ease of extension, ultimately contributing to a more robust and user-friendly
platform.
Intent: Defines an interface for creating an object but lets subclasses alter the type of objects
that will be created.
The Factory pattern addresses challenges by centralizing the object creation process, making it easier to manage
and extend the types of products offered by the system.
APPLICABILITY:
You want to encapsulate the creation logic of different types of objects to make the codebase more
modular and maintainable.
The system needs to dynamically create objects based on user input, allowing for customization and
flexibility in product offerings.
You anticipate that new types of products or customizations will be added in the future, and you want
to simplify the process of integrating these new variations.
The system requires a centralized place for object creation to avoid cluttering the main business logic
with instantiation details.
You want to decouple the instantiation process from the system's core logic, enabling changes to
object creation without affecting the existing codebase.
STRUCTURE:
The Builder pattern is proposed to improve the Online Coffee Ordering System by providing a
step-by-step construction process for creating complex objects (like customized coffee orders). This
pattern is particularly useful for handling scenarios where multiple parts need to be assembled, and the
object being constructed requires different configurations, such as choosing a coffee type, sugar level,
milk option, and various add-ons. By breaking the construction process into smaller steps, the Builder
pattern allows customers to customize their orders without overwhelming them with all options at once.
In the context of the Online Coffee Ordering System, the Builder pattern can be applied to
manage the creation of customized coffee orders by building the coffee in stages—adding components
like type, sugar level, and milk as separate steps. This incremental approach makes it easy to modify,
extend, or customize the process. The system can later use the same Builder to create different coffee
configurations based on new customer preferences without changing existing logic.
For instance, when a customer selects a coffee, the system can use a Builder to assemble the final
coffee order by choosing the coffee type, adding milk, selecting the sugar level, and choosing flavorings
or other add-ons step by step. This approach allows for more control over the creation of complex orders
and helps avoid errors in the customization process.
By applying the Builder pattern, the Online Coffee Ordering System achieves several key
benefits:
Incremental Construction: Coffee orders are created in stages, allowing users to review or modify each
step.
Customization: Users can customize each part of the order (e.g., type, sugar, milk, add-ons) without
dealing with a complex interface.
Reusability: The Builder can be reused to create different variations of coffee orders by combining
different components.
Moreover, the Builder pattern aligns with the system’s goal of improving user experience by
making the customization process intuitive and less error-prone, ultimately leading to a more flexible
and user-friendly system.
Intent: Separate the construction of a complex object from its representation, allowing the same
construction process to create different representations.
Managing complex object creation (like customized coffee orders) step by step.
Enabling customization and flexibility while reducing the complexity of the user interface.
Providing an easy way to modify the process by adjusting the steps in the order-building process.
APPLICABILITY:
You need to construct complex objects that consist of various components (e.g., different types of coffee,
sugar, milk, add-ons).
The construction process involves multiple steps or stages that may vary based on user preferences.
You want to allow users to customize orders in a controlled, incremental manner, ensuring flexibility in
product offerings.
You want to decouple the object-building process from the final representation, so that the system can build
different variations of coffee from the same basic structure.
The system should allow easy modification or extension of the construction process without altering the
existing codebas
STRUCTURE:
PATTERN USED: COMMAND PATTERN
The Command pattern is proposed to enhance the Online Coffee Ordering System by
encapsulating customer requests (such as placing, modifying, or canceling an order) as command objects.
This pattern allows the system to decouple the sender (e.g., customer or system interface) from the
objects that execute specific commands (e.g., baristas or automated systems). With this approach,
various actions such as ordering coffee, adding extras, or canceling an order can be treated as separate
command objects that can be queued, logged, or undone, offering better flexibility and control.
In the context of the Online Coffee Ordering System, the Command pattern can be used to handle
the execution of different operations related to coffee orders. Each operation (such as placing an order,
adding sugar, canceling the order, or modifying add-ons) is encapsulated into a command object, which
is processed by the system. This provides the flexibility to queue up actions, undo certain operations, or
track customer requests more efficiently.
For instance, when a customer places an order, the system creates a command object representing
that request. If the customer decides to modify the order, another command object is issued to update the
request. If they cancel the order, the command object is created for cancellation. This makes the process
more flexible by allowing actions like undoing, queuing, or logging operations.
By applying the Command pattern, the Online Coffee Ordering System achieves several key
benefits:
Decoupling of Sender and Receiver: The system decouples the customer’s input from the actions that
are carried out, providing flexibility in how requests are processed.
Command Logging: Orders and modifications can be logged, tracked, or even undone, providing better
control over customer interactions.
Queueing of Operations: Customer requests (e.g., placing or modifying orders) can be queued and
executed sequentially or in bulk, optimizing workflow for workers.
Moreover, the Command pattern aligns with the system’s objectives of improving order
management, enhancing flexibility, and allowing operations like undoing or queuing commands,
contributing to a more efficient and customer-friendly platform.
Intent: Encapsulates a request as an object, thereby allowing for parameterization of clients with
different requests, queueing of requests, and logging or undoing of operations.
Decoupling the sender and receiver, allowing the system to handle customer requests more flexibly.
Enabling the system to queue, log, or undo requests, improving control and responsiveness to changes in
orders.
Allowing operations to be added or modified without changing the core logic of the system.
APPLICABILITY:
You want to parameterize objects with operations to be executed at a later time (e.g., customer orders,
modifications, cancellations).
The system needs to log, queue, or undo certain operations (e.g., modifying or canceling coffee orders).
You want to decouple the sender (e.g., customer) from the receiver (e.g., barista or system that processes
orders).
You need to implement an undo feature that can revert or cancel operations based on customer input.
The system should support complex workflows by allowing actions to be queued and executed in sequence.
STRUCTURE:
How the Patterns Work Together
Factory + Builder: The Factory Pattern is responsible for creating base coffee objects like
espresso, latte, or cappuccino, while the Builder Pattern assembles these objects with additional
customizations such as sugar level, milk type, or size.
Factory + Command: The Factory Pattern handles the instantiation of coffee orders, while
the Command Pattern encapsulates user actions like placing, modifying, or canceling orders, ensuring
that order management is consistent and dynamic.
Builder + Command: The Builder Pattern creates highly customized coffee orders step by
step, and the Command Pattern queues and executes these customizations as distinct actions, allowing or
efficient management of complex orders and enabling features like undo or redo.
2. Composite Pattern
3. Bridge Pattern
4. Singleton Pattern
/OnlineCoffeeOrderingSystem
├── Coffee.java
├── Espresso.java
├── Cappuccino.java
├── CoffeeFactory.java
├── CoffeeOrder.java
├── Command.java
├── PlaceOrderCommand.java
├── CancelOrderCommand.java
├── CoffeeOrderInvoker.java
|── OrderManager.java
└── Main.java
1. Coffee.java
2. Espresso.java
3. Cappuccino.java
@Override
public void brew() {
System.out.println("Brewing Cappuccino");
}
}
4. CoffeeFactory.java
5. CoffeeOrder.java
6. Command.java
7. PlaceOrderCommand.java
@Override
public void execute() {
System.out.println("Placing order: " + coffeeOrder.toString());
}
}
8. CancelOrderCommand.java
10.Main.java
1. SYSTEM OVERVIEW
3. PROCESS FLOW
[1] User Input → [2] Coffee Creation → [3] Order Building → [4] Order Processing
OUTPUT:
P
9. Modifications
The Singleton pattern is proposed for the Online Coffee Ordering System to ensure a single,
centralized point of control for managing critical system components that should exist as only one
instance throughout the application's lifecycle. This pattern is particularly valuable for managing shared
resources, maintaining system-wide state, and coordinating access to unique system components like the
order management system, inventory tracker, or global configuration settings.
In the context of the Online Coffee Ordering System, the Singleton pattern can be applied to
components such as the OrderManager, InventoryController, or PaymentGateway, where having
multiple instances could lead to data inconsistency or resource conflicts. For example, the system needs
only one inventory tracking system to maintain accurate stock levels across all transactions, making it an
ideal candidate for the Singleton pattern.
When a customer places a coffee order, the system accesses the single instance of these critical
components to process the order, update inventory, and handle payment processing, ensuring consistency
and proper resource management throughout the entire ordering process. This centralized control helps
prevent issues like double-booking of resources or inconsistent state management.
By implementing the Singleton pattern, the Online Coffee Ordering System achieves several
key benefits: · Resource Management: Ensures efficient use of system resources by maintaining only
one instance of resource-intensive components. · Data Consistency: Maintains consistent state across
the entire application by providing a single source of truth. · Global Access Point: Offers a centralized
access point for vital system operations and shared resources.
The Singleton pattern supports the system's requirements for reliable order processing, accurate
inventory tracking, and consistent system state management, contributing to a robust and dependable
coffee ordering platform.
Intent: Ensure a class has only one instance and provide a global point of access to it,
guaranteeing centralized control over key system operations.
The Singleton pattern addresses challenges by: · Preventing multiple instances of critical
system components that could lead to data inconsistency · Providing controlled access to shared
resources across the entire application · Ensuring system-wide coordination for operations like inventory
management and order processing
APPLICABILITY:
STRUCTURE:
CODE:
// 3. Public static method to get instance - only way to get the OrderManager
public static OrderManager getInstance() {
if (instance == null) {
synchronized (OrderManager.class) { // Thread safety
if (instance == null) { // Double-check locking
instance = new OrderManager();
}
}
}
return instance;
}
}
Singelton Pattern Output: (Showcase)
10.REFERENCES: