You are on page 1of 5

1.

E-commerce Order Processing System

Imagine an e-commerce company that sells a wide range of products online. They have a complex
order processing system that involves handling various steps, including inventory management,
payment processing, and shipping.

The e-commerce system needs to notify customers about the status of their orders. Customers want to
receive notifications when their orders are confirmed, shipped, and delivered. When an order's status
changes, such as being confirmed or shipped, the system notifies the relevant customers through their
preferred communication channels, like email or SMS. This pattern ensures that customers stay
updated about their orders in real-time.

The e-commerce system includes a payment gateway integration responsible for processing payments
securely. Consistent and secure payment processing throughout the application has to be ensured.
This ensures that there's only one instance of the payment gateway that handles all payment
transactions. The system avoids potential concurrency issues and maintains a single point of contact
for payment processing.

In the e-commerce system, there's a need to integrate with various shipping carriers that use different
APIs and data formats. It bridges between the central system and the diverse shipping carriers. It
needs to translate the shipping carrier's specific API into a common interface that the central system
can understand. This allows the e-commerce system to interact with different shipping carriers
seamlessly, regardless of their unique protocols. It also enables the system to switch between shipping
carriers easily without modifying the core code.

Identify all the design patterns needed to implement the scenario with explanation. Now, show the
structures of your implementation.

2.
a) In the following code-segment, there exists at least three major code smells.
a. Identify the smells and write the name of the smells. [Marks: 3]
b. Propose makeovers for the mentioned code smells. [Marks: 6]

class Vehicle { class RepairShop {

void startEngine() { void repairVehicle(Vehicle vehicle) {

System.out.println("Engine started"); if (vehicle instanceof Car) {


((Car) vehicle).startCar();
}
} else if (vehicle instanceof Bike) {
}
((Bike) vehicle).startBike();
}
class Car extends Vehicle {
void startCar() { }

System.out.println("Car started"); // More methods

} void performCarDiagnostic(Car car) {


car.startCar();
}
// ... do car-specific diagnostic
}
class Bike extends Vehicle {
void performBikeMaintenance(Bike bike) {
void startBike() {
bike.startBike();
System.out.println("Bike started"); // ... do bike-specific maintenance
} }
} void displayCarInformation(Car car) {
car.startCar();
}
}

b) Give examples of smells and makeovers of the following categories: decompose


conditionals, preserve whole objects, and introduce assertions. [Marks: 3x2 = 6]

3. Consider the following function

public static String calculateShipping(int weight, String destination) {


String shippingMethod;

if (weight <= 0) {
shippingMethod = "Invalid";
}
else {
if (destination.equals("Domestic")) {
if (weight <= 1) {
shippingMethod = "Standard";
}
else {
shippingMethod = "Priority";
}
}
else {
if (weight <= 3) {
shippingMethod = "International";
}
else {
shippingMethod = "Express International";
}
}
}
}
a. Draw the CFG for the code fragment. [7 marks]
b. Compute the cyclomatic complexity number C [3 marks]

4.

Class A{
void foo();
void moo();
}
Class B extends A{
void coo();
void koo();
void moo();
void loo();
}
Class C extends B{
void coo();
void koo();
void roo();
}

Calculate the value of Specialization index (SIX). [5 marks]

5.

Mita was excited to start her new job as a software engineer at a tech startup. She was given a task to develop a
feature for the company's app. However, after finishing her code, her senior found several code smells. She
spent time researching and learning about best coding practices, and how to eliminate code smells. Lastly, she
worked on refactoring her code.

1. Write down any code smells that may have caught the attention of Mita’s boss
[2]
2. Refactor the program as needed
[4]
3. What is the purpose of refactoring [4]
//calculating the Surface of Cylinder with the
public class Calculator { radius and height
//calculating the perimeter of Circle with the
radius public double calCSA(double r, double h) {
public double calPC(double r) { double pi = 3.14;
double pi = 3.14; double result= (2 * pi * r * h) + (2 * pi * r * r);
double result = 2 * pi * r; return result;
return result; }
}
//calculating the Area of Sphere with the radius //calculating the Surface area of Cone with the
public double calSSA(double r) { radius and height
double pi = 3.14; public double calCSA(double r, double h, int v, int
double result= 4 * pi * r * r; t, int g) {
return result; double pi = 3.14;
} double s = Math.sqrt((r * r) + (h * h));
double result= pi * r * s + pi * r * r;
return result;
}
}

6.

Question: Figure out the Cyclomatic Complexity of the following code snippet [10]
while (temperature > 0) {
if (isCoolingSystemOn) {
for (int i = 0; i < fanSpeed; i++) {
if (temperature < maxTemperature) {
// Adjust fan speed and cooling logic
temperature -= coolingRate;
} else {
// Alert about high temperature
System.out.println("Temperature is too high!");
}
}
} else {
// Turn off cooling system temporarily
isCoolingSystemOn = false;
temperature += warmingRate;
}
// Check and perform other system operations
if (isEmergencyMode) {
// Activate emergency cooling procedures
}
}
7. Question: Imagine you are part of a team designing a new decentralized application
(dApp) on a blockchain platform. One of the critical features of this dApp is that certain
nodes need to be informed whenever a particular state in the system changes.
Your task is to design a mechanism that allows:
1. Registration of nodes that wish to be informed of state changes.
2. Deregistration of nodes that no longer want to be informed.
3. Broadcasting of state changes to all registered nodes.
(a) What kind of design pattern will you use for this application and why? [2]
(b) Provide code snippets for the critical methods involved in your design. [5]
(c) Describe a modification to your design that would allow for notifying only a
subset of nodes based on certain criteria (e.g., nodes possessing a specific
property). [3]

You might also like