0% found this document useful (0 votes)
32 views33 pages

DP FR

The document outlines the design and implementation of an Online Coffee Ordering System that addresses challenges related to customizable orders and staff efficiency using Factory, Builder, and Command design patterns. These patterns streamline order processing, enhance user experience, and ensure scalability and maintainability of the system. Key functionalities include product management, user management, ordering and payment, and reporting, all aimed at improving customer satisfaction and operational efficiency.

Uploaded by

gx4z4ytf8z
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views33 pages

DP FR

The document outlines the design and implementation of an Online Coffee Ordering System that addresses challenges related to customizable orders and staff efficiency using Factory, Builder, and Command design patterns. These patterns streamline order processing, enhance user experience, and ensure scalability and maintainability of the system. Key functionalities include product management, user management, ordering and payment, and reporting, all aimed at improving customer satisfaction and operational efficiency.

Uploaded by

gx4z4ytf8z
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 33

DESIGN PATTERNS

SWE2019

SLOT: A2

Online Coffee Ordering System

Review - 3

Faculty Name: Prof. Ushapreethi P

Group Members:

SL NAME REGISTRATION NO.


NO.

1. Raafid Afraaz G 22MIS0258

2. Mohammed Izhan I 22MIS0336


1. PROBLEM STATEMENT:

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.

Meanwhile, staff members face challenges managing the increasing complexity of


customer requests. Each coffee order includes multiple customizations, such as size,
flavor, sugar level, and additional ingredients, which must be processed manually. This
increases cognitive load, slows down service, and causes bottlenecks in order
management, especially when handling large group orders or catering services.

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 Builder Pattern complements this by allowing users to specify complex


customizations, such as the size, sugar level, or add-ons, in a structured and sequential way.
Instead of manually handling each attribute individually, the Builder simplifies the process by
constructing the final coffee object step by step, ensuring that every detail is captured correctly
and reducing the chances of errors during order placement.

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.

Key Aspects of the Domain:

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.

Ordering and Payment:

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.

Search and Discovery:

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.

Reporting and Analytics:

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.

Integration and Extensibility:

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.

Security and Data Privacy:

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.

5. DETAILED DESIGN PATTERN

PATTERN USED: FACTORY PATTERN

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:

Use the Factory pattern when:

 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:

FACTORY PATTERN FOR ONLINE COFFEE ORDERING SYSTEM


PATTERN USED: BUILDER PATTERN

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.

The Builder pattern addresses challenges by:

 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:

Use the Builder pattern when:

 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.

The Command pattern addresses challenges by:

 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:

Use the Command pattern when:

 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.

Class/Component Design Description


Pattern
CoffeeFactory Factory Creates instances of different
Method coffee types based on user
input.
CoffeeBuilder Builder Step-by-step customization
of coffee orders, including
flavor, size, sugar level,
and add-ons.
CoffeeOrderCommand Command Encapsulates actions such as
placing, modifying, or canceling
coffee orders.
Manages the entire process
OrderManager Singleton
of order handling, ensuring
only one instance controls
the flow.
Represents customer
CustomerActions Command
interactions like placing a
new order or modifying
existing ones.
IMPLEMENTATION:

1. Factory Method Pattern

Where it's used:


The CoffeeFactory class handles the creation of various coffee types such as espresso, latte,
cappuccino, and others based on customer input.

Why it’s used:


The Factory Method Pattern abstracts the instantiation process, ensuring that the system can
create coffee objects without directly specifying their concrete classes. This allows the system to easily
handle future modifications or the addition of new coffee types.

2. Composite Pattern

Where it's used:


The CoffeeBuilder class is responsible for handling coffee customizations like sugar level, milk
type, and additional toppings (e.g., whipped cream, caramel).

Why it’s used:


The Builder Pattern enables the construction of complex coffee orders step by step. Customers
can customize their coffee by specifying various parameters (size, sugar, milk type, etc.) without directly
modifying the underlying coffee class. This promotes the flexibility to create highly customized
orders while ensuring code maintainability.

3. Bridge Pattern

Where it's used:


The CoffeeOrderCommand encapsulates the actions a customer can perform, such as placing an
order, modifying an order, or canceling an order.

Why it’s used


The Command Pattern decouples the order actions from the client, allowing the system to
manage customer requests dynamically. This pattern is beneficial when handling operations like
queuing, undoing,
or logging actions for orders.

4. Singleton Pattern

Where it might be used:


The OrderManager class, which handles the overall flow of coffee orders.

Why it might be used:


The Singleton Pattern ensures that there is only one instance of the OrderManager class
managing
all orders. This provides centralized control over the order process, including order queueing,
processing, and cancellation.
6. CODE:

/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

public abstract class Coffee {


protected String name;
protected double price;

public Coffee(String name, double price) {


this.name = name;
this.price = price;
}

public abstract void brew();


}

2. Espresso.java

public class Espresso extends Coffee {


public Espresso() {
super("Espresso", 100.0);
}
@Override
public void brew() {
System.out.println("Brewing Espresso");
}
}

3. Cappuccino.java

public class Cappuccino extends Coffee {


public Cappuccino() {
super("Cappuccino", 120.0);
}

@Override
public void brew() {
System.out.println("Brewing Cappuccino");
}
}

4. CoffeeFactory.java

public class CoffeeFactory {


public static Coffee createCoffee(String type) {
if (type.equalsIgnoreCase("Espresso")) {
return new Espresso();
} else if (type.equalsIgnoreCase("Cappuccino")) {
return new Cappuccino();
} else {
return null;
}
}
}

5. CoffeeOrder.java

public class CoffeeOrder {


private String coffeeType;
private String size;
private boolean milk;
private boolean sugar;
private CoffeeOrder(CoffeeOrderBuilder builder) {
this.coffeeType = builder.coffeeType;
this.size = builder.size;
this.milk = builder.milk;
this.sugar = builder.sugar;
}

public static class CoffeeOrderBuilder {


private String coffeeType;
private String size;
private boolean milk;
private boolean sugar;

public CoffeeOrderBuilder(String coffeeType) {


this.coffeeType = coffeeType;
}

public CoffeeOrderBuilder size(String size) {


this.size = size;
return this;
}

public CoffeeOrderBuilder milk(boolean milk) {


this.milk = milk;
return this;
}

public CoffeeOrderBuilder sugar(boolean sugar) {


this.sugar = sugar;
return this;
}

public CoffeeOrder build() {


return new CoffeeOrder(this);
}
}
@Override
public String toString() {
return "CoffeeOrder{" +
"coffeeType='" + coffeeType + '\'' +
", size='" + size + '\'' +
", milk=" + milk +
", sugar=" + sugar +
'}';
}
}

6. Command.java

public interface Command {


void execute();
}

7. PlaceOrderCommand.java

public class PlaceOrderCommand implements Command {


private CoffeeOrder coffeeOrder;

public PlaceOrderCommand(CoffeeOrder coffeeOrder) {


this.coffeeOrder = coffeeOrder;
}

@Override
public void execute() {
System.out.println("Placing order: " + coffeeOrder.toString());
}
}

8. CancelOrderCommand.java

public class CancelOrderCommand implements Command {


@Override
public void execute() {
System.out.println("Order canceled.");
}
}
9. CoffeeOrderInvoker.java

public class CoffeeOrderInvoker {


private Command command;

public void setCommand(Command command) {


this.command = command;
}

public void processOrder() {


command.execute();
}
}

10.Main.java

public class Main {


public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

// Factory Pattern Usage


// Ask user for coffee type
System.out.print("Enter coffee type (e.g., Espresso, Cappuccino): ");
String coffeeType = scanner.nextLine();

// Ask user for size


System.out.print("Enter size (Small, Medium, Large): ");
String size = scanner.nextLine();

// Ask user for milk preference


System.out.print("Do you want milk? (yes/no): ");
boolean milk = scanner.nextLine().equalsIgnoreCase("yes");

// Ask user for sugar preference


System.out.print("Do you want sugar? (yes/no): ");
boolean sugar = scanner.nextLine().equalsIgnoreCase("yes");
// Builder Pattern Usage
CoffeeOrder order = new CoffeeOrder.CoffeeOrderBuilder(coffeeType)
.size(size)
.milk(milk)
.sugar(sugar)
.build();

System.out.println("Your coffee order: " + order);

// Command Pattern Usage


CoffeeOrderInvoker invoker = new CoffeeOrderInvoker();
Command placeOrder = new PlaceOrderCommand(order);
invoker.setCommand(placeOrder);
invoker.processOrder();

// Inform user about coffee readiness time


System.out.println("Your coffee will be ready in 10 minutes.");

// Option to cancel the order


System.out.print("Do you want to cancel the order? (yes/no): ");
boolean cancel = scanner.nextLine().equalsIgnoreCase("yes");
if (cancel) {
Command cancelOrder = new CancelOrderCommand(order);
invoker.setCommand(cancelOrder);
invoker.processOrder();
System.out.println("Your order has been canceled.");
}
System.out.println("Thank You ");
}
}
Snippets:
7. COLLOBAORATION (FLOW)

1. SYSTEM OVERVIEW

┌─ User Interface (Main.java)


└─ Core Components
├─ Singleton Pattern: Order Management
├─ Factory Pattern: Coffee Creation
├─ Builder Pattern: Order Construction
└─ Command Pattern: Order Processing
2. PATTERN INTERACTIONS & RESPONSIBILITIES

A. SINGLETON PATTERN (Order Management)


- Core Purpose: Global order tracking system
- Single OrderManager instance that:
* Generates unique order IDs
* Maintains order history
* Handles concurrent orders
* Provides centralized order database
- Benefits: Thread-safe, memory efficient, consistent tracking

B. FACTORY PATTERN (Coffee Creation)


- Core Purpose: Coffee type instantiation
- Structure:
* Abstract Coffee class
* Concrete classes: Espresso, Cappuccino
* CoffeeFactory: Creates specific coffee instances
- Benefits: Encapsulates coffee creation, easy to add new types

C. BUILDER PATTERN (Order Construction)


- Core Purpose: Complex order assembly
- Components:
* CoffeeOrder: Final product
* CoffeeOrderBuilder: Constructs orders step by step
- Customization Options:
* Coffee type
* Size
* Milk preference
* Sugar preference
- Benefits: Flexible order construction, clear separation of concerns
D. COMMAND PATTERN (Order Processing)
- Core Purpose: Order operation handling
- Components:
* Command Interface
* PlaceOrderCommand
* CancelOrderCommand
* CoffeeOrderInvoker
- Benefits: Decoupled order execution, easy to add new commands

3. PROCESS FLOW

[1] User Input → [2] Coffee Creation → [3] Order Building → [4] Order Processing

- Step 1: Gather user preferences


- Step 2: Create specific coffee type using Factory
- Step 3: Build complete order using Builder
- Step 4: Process order using Command & Singleton
4. ERROR HANDLING
- Invalid coffee types handled by Factory
- Order validation in Builder
- Order state management in Singleton
- Operation validation in Command

OUTPUT:

P
9. Modifications

PATTERN USED: SINGELTON PATTERN

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:

Use the Singleton pattern when:


 Only one instance of a class should exist throughout the system's lifecycle (e.g., order management
system, inventory tracker).
 Shared resources need to be accessed and managed from a single point of control.
 Global state needs to be maintained consistently across the entire application .
 Multiple instances of a component could cause conflicts or inconsistencies in system operation .
 Centralized control is required for coordinating system-wide operations and resource management.

STRUCTURE:
CODE:

public class OrderManager {


// 1. Private static instance - only one copy exists
private static OrderManager instance;

// 2. Private constructor - prevents direct instantiation


private OrderManager() {
orders = new HashMap<>();
nextOrderId = 1;
}

// 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:

1. System Design for Online Coffee Ordering System - GeeksforGeeks


2. Design and Implementation of Online Coffee Ordering System (researchgate.net)
3. E-commerce System Design Patterns and Best Practices - Medium
4. Factory Design Pattern - GeeksforGeeks
5. Textbook: Design Patterns: Elements of Reusable Object-Oriented Software by Erich
Gamma, Richard Helm, Ralph Johnson, and John Vlissides.
6. Online Ordering Systems: Design and Implementation - IEEE Xplore
7. "Applying Design Patterns in Online Ordering Systems: A Systematic Review" - IEEE
Transactions on Software Engineering
8. Head First Design Patterns: Building Extensible and Maintainable Object-Oriented
Software by Eric Freeman and Elisabeth Robson
9. Java Design Patterns: A Tutorial - Oracle Technical Network
10. "Design and Implementation of Food Ordering System Using Design Patterns" -
International Journal of Computer Applications

Group contribution details:

22MIS0336 (Izhan): Conceptual and Design Focus

 Problem Statement (Intent)


 Motivation for Choosing the Work
 Domain of the Project
 Design Patterns Involvement
 References for Domain and Motivation (URLs)
 Structure for Each Design Pattern

22MIS0258 (Raafid): Implementation and Output Focus

 Code for Each Component


 Collaboration of Your Code (Flow)
 Sample Output Screenshots
 Modifications Given by Faculty
 Details of Design Patterns with Respect to the Scenario
 Documentation

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy