0% found this document useful (0 votes)
37 views8 pages

Justifications

The document discusses several design patterns used in an ice cream ordering system: - Observer pattern is used to notify components like order status, feedback, and tracking systems of state changes. - Strategy pattern allows switching between payment methods like credit cards without changing client code. - Builder pattern simplifies complex ice cream order creation with multiple steps like flavors and toppings. - Chain of responsibility handles order customizations independently with handlers like flavors and toppings. - State pattern manages different order states like placed and delivered through encapsulated state objects.

Uploaded by

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

Justifications

The document discusses several design patterns used in an ice cream ordering system: - Observer pattern is used to notify components like order status, feedback, and tracking systems of state changes. - Strategy pattern allows switching between payment methods like credit cards without changing client code. - Builder pattern simplifies complex ice cream order creation with multiple steps like flavors and toppings. - Chain of responsibility handles order customizations independently with handlers like flavors and toppings. - State pattern manages different order states like placed and delivered through encapsulated state objects.

Uploaded by

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

Observer Pattern

 I’ve used this pattern for updating order status, tracking and feedback systems. Using Observer
Pattern is useful and efficient in scenario’s like an object want’s to notify a list of observers of
the state changes. Here in my implementation, it makes sure that the changes in order status
and feedback is correctly communicated with the relevant components where it gives real time
updates and also improves the user’s experience.

Strategy Pattern
 I’ve used this pattern to the payment processing where strategy patten have the facility and the
flexibility to switch between different payment methods like credit cards, debit cards and other
wallets. So because of using strategy pattern it is easy to add new payment methods and also
maintain existing payment methods without changing the client code.

Builder Pattern
 I’ve used this pattern to implement complex ice cream orders. Because of using this pattern it
simplifies the process of creation of an order where it have several steps like choosing flavours,
toppings, syrups and so on and also because of using Builder Pattern it makes easy to read the
code and also maintain. This facilitates customers to customize and order easily.

Chain of Responsibility Pattern


 I’ve used this pattern to processing order customizations where it facilitates different handlers
like flavours, toppings, syrup handlers in-order to process the desired part of the order
independently. So because of using Chain of Responsibility Pattern it makes to add new
customizations or modify the existing ones without effecting the other parts of the codes.

State Pattern
 I’ve used State Pattern to manage different stages or states of an order like placed, in
preparation and out for delivery. So because of using State Pattern it provides a good and clear
structure for changing through different states in an order, it makes the code more robust
because it makes sures that the state-related things are encapsulated within state objects.
Command Pattern
 I’ve used this pattern to represent the actions of the user such as placing an order, giving
feedback. Command Pattern encapsulates the request of an object so it facilitates users to
parameterize clients from different requests, queue or log requests and also it supports to
operations that cannot be done.

Decorator Pattern
 I’ve used this pattern to allows for additional features to be added to an order at runtime
without changing the classes that are there , enhancing flexibility and maintainability.

Observer Pattern
interface OrderStatusObserver {

void updateStatus(String status);

interface FeedbackObserver {

void receiveFeedback(String feedback);

interface OrderTrackingObserver {

void updateOrderStatus(String status);

class OrderStatus implements OrderStatusObserver {

@Override

public void updateStatus(String status) {

System.out.println("Order Status: " + status);

}
class FeedbackSystem implements FeedbackObserver {

@Override

public void receiveFeedback(String feedback) {

System.out.println("Feedback received: " + feedback);

class OrderTrackingSystem implements OrderTrackingObserver {

@Override

public void updateOrderStatus(String status) {

System.out.println("Order Status: " + status);

class BasicIceCream implements IceCream {

// Observer Lists

private List<OrderStatusObserver> orderStatusObservers = new ArrayList<>();

private List<FeedbackObserver> feedbackObservers = new ArrayList<>();

private List<OrderTrackingObserver> orderTrackingObservers = new ArrayList<>();

// Methods to add and notify observers

@Override

public void addObserver(OrderStatusObserver observer) { /* ... */ }

@Override

public void addObserver(FeedbackObserver observer) { /* ... */ }

@Override

public void addObserver(OrderTrackingObserver observer) { /* ... */ }

@Override
public void notifyOrderStatus(String status) { /* ... */ }

@Override

public void notifyFeedback(String feedback) { /* ... */ }

@Override

public void notifyOrderTracking(String status) { /* ... */ }

Strategy Pattern
interface PaymentStrategy {

void processPayment(double amount);

class CreditCardPayment implements PaymentStrategy {

private LoyaltyProgram loyaltyProgram;

@Override

public void processPayment(double amount) {

System.out.println("Processing credit card payment: $" + amount);

loyaltyProgram.earnPoints(amount);

class BasicIceCream implements IceCream {

private PaymentStrategy paymentStrategy;

@Override

public void setPaymentStrategy(PaymentStrategy paymentStrategy) {

this.paymentStrategy = paymentStrategy;
}

@Override

public void processPayment(double amount) {

paymentStrategy.processPayment(amount);

Builder Pattern
class BasicIceCream {

public static class Builder {

private List<String> flavors = new ArrayList<>();

private List<String> toppings = new ArrayList<>();

private List<String> syrups = new ArrayList<>();

private String name;

public Builder addFlavor(String flavor) { /* ... */ }

public Builder addTopping(String topping) { /* ... */ }

public Builder addSyrup(String syrup) { /* ... */ }

public Builder setName(String name) { /* ... */ }

public BasicIceCream build() { /* ... */ }

}
Chain of Responsibility Pattern
abstract class CustomizationHandler {

protected CustomizationHandler nextHandler;

public void setNextHandler(CustomizationHandler nextHandler) {

this.nextHandler = nextHandler;

public abstract void handleRequest(IceCream iceCream);

class FlavorHandler extends CustomizationHandler {


@Override
public void handleRequest(IceCream iceCream) {
System.out.println("Handling flavor customization");
if (nextHandler != null) {
nextHandler.handleRequest(iceCream);
}
}
}

class ToppingHandler extends CustomizationHandler {


@Override
public void handleRequest(IceCream iceCream) {
System.out.println("Handling topping customization");
if (nextHandler != null) {
nextHandler.handleRequest(iceCream);
}
}
}

class SyrupHandler extends CustomizationHandler {


@Override
public void handleRequest(IceCream iceCream) {
System.out.println("Handling syrup customization");
if (nextHandler != null) {
nextHandler.handleRequest(iceCream);
}
}
}

State Pattern
interface OrderState {

void placeOrder(IceCream iceCream);

void prepareOrder(IceCream iceCream);

void deliverOrder(IceCream iceCream);

class PlacedState implements OrderState {


@Override
public void placeOrder(IceCream iceCream) {
System.out.println("Order placed.");
}

@Override
public void prepareOrder(IceCream iceCream) {
System.out.println("Preparing the order.");
}

@Override
public void deliverOrder(IceCream iceCream) {
System.out.println("Cannot deliver, order not prepared.");
}
}

class PreparationState implements OrderState {


@Override
public void placeOrder(IceCream iceCream) {
System.out.println("Order already placed.");
}

@Override
public void prepareOrder(IceCream iceCream) {
System.out.println("Order in preparation.");
}
@Override
public void deliverOrder(IceCream iceCream) {
System.out.println("Cannot deliver, order not prepared.");
}
}

class DeliveryState implements OrderState {


@Override
public void placeOrder(IceCream iceCream) {
System.out.println("Order already placed.");
}

@Override
public void prepareOrder(IceCream iceCream) {
System.out.println("Order already prepared.");
}

@Override
public void deliverOrder(IceCream iceCream) {
System.out.println("Delivering the order.");
}
}

You might also like