My Solution for Design a Warehouse Management System with Score: 5/10
by pulse_alchemy255
Requirements
This will be a warehouse management system
There can be many way but in this one this how it will be.
- Product -> Stock Keeping quantity , price , quantity
- Warehouse -> storage area , total capacity , overall inventory
- Order -> customer information , order date and status
- Inventory -> Stock levels , tracking incoming and outgoing items from warehouse
- Shipment -> incoming and outgoing shipments, tracking which item goes out and received in.
Define Core Objects
Core objects will be as follows:
class Product{
public:
string id;
string name;
float price;
int quantity;
};
We should also have customer information
class Customer{
public:
string name;
string address;
string emailAddress
string phoneNumber;
};
Order
class Order{
public:
string id;
Customer information;
vector<Product> p;
Status s;
};
Another one will be inventory
class Inventory{
public:
vector<Product> P;
int totalStock;
};
We can define enum for status
enum Status { Success, Failure, Pending, Shipped };
Another one should be Shipment
class Shipment{
public:
Order order;
status s;
};
Another can be warehouse
class Warehouse{
public:
int capacity;
string location;
vector<Inventory> inventory;
};
Analyze Relationships
Warehouse will contain multiple inventories.
Inventory will contain multiple products
Order will contain multiple products
Establish Hierarchy
So we can have inheritance.
Both order and shipment have statuses
class Transaction {
public:
std::string id;
Status status; // Both orders and shipments have statuses
// Methods for managing status, tracking, etc.
};
class Order : public Transaction {
public:
Customer customerInfo;
std::vector<Product> products;
// Order-specific methods
};
class Shipment : public Transaction {
public:
Order order;
// Shipment-specific methods
};
We can extend our warehouse to hold different kind of products so in order to do that we can add more scalibility and reusable code
class Product {
public:
std::string id;
std::string name;
float price;
int quantity;
virtual void displayProductDetails() const {
// Basic product details
}
};
class PerishableProduct : public Product {
public:
std::string expirationDate;
void displayProductDetails() const override {
// Display perishable product details including expiration date
}
};
class ElectronicProduct : public Product {
public:
int warrantyPeriod;
void displayProductDetails() const override {
// Display electronic product details including warranty
}
};
Design Patterns
Consider using design patterns (e.g., Factory, Singleton, Observer, Strategy) that fit the problem...
Define Class Members (write code)
Attributes: For each class, define the attributes (data) it will hold...
Methods: Define the methods (functions) that operate on the attributes. Ensure they align with the object's responsibilities and adhere to the principle of encapsulation.
#include <iostream>
#include <vector>
#include <string>
#include <regex>
using namespace std;
enum Status { Success, Failure, Pending, Shipped };
class Product {
public:
std::string id;
std::string name;
float price;
int quantity;
// Constructor for Product
Product(std::string id, std::string name, float price, int quantity)
: id(id), name(name), price(price), quantity(quantity) {
}
};
// Derived class PerishableProduct
class PerishableProduct : public Product {
public:
std::string expirationDate;
// Constructor for PerishableProduct
PerishableProduct(std::string id, std::string name, float price, int quantity, std::string expirationDate)
: Product(id, name, price, quantity), expirationDate(expirationDate) {
}
void displayProductDetails() {
std::cout << "Perishable Product: " << name << ", Expiration Date: " << expirationDate << std::endl;
}
};
// Derived class ElectronicProduct
class ElectronicProduct : public Product {
public:
int warrantyPeriod;
// Constructor for ElectronicProduct
ElectronicProduct(std::string id, std::string name, float price, int quantity, int warrantyPeriod)
: Product(id, name, price, quantity), warrantyPeriod(warrantyPeriod) {
}
void displayProductDetails() {
std::cout << "Electronic Product: " << name << ", Warranty Period: " << warrantyPeriod << " months" << std::endl;
}
};
class Customer {
public:
std::string name;
std::string address;
std::string emailAddress;
std::string phoneNumber; // Use string for flexibility
// Constructor and methods for validation, etc.
Customer(string name , string address , string email , string phone){
name = name;
address = address;
email = email;
phoneNumber = phone;
}
bool validateEmail(string email){
regex pattern(R"((\w+)(\.{1}\w+)*@(\w+)(\.\w{2,3})+)");
return std::regex_match(email, pattern);
}
bool validatePhone(string phone){
int size = phone.size();
return size == 9 ? true : false;
}
};
class Inventory {
public:
static std::unordered_map<std::string, Product> productMap; // Static map for quick lookup
// Static method to initialize the inventory with products
static void initializeInventory(const std::vector<Product>& products) {
for (const auto& p : products) {
productMap[p.id] = p; // Insert product into the map
}
}
// Static method to check if the product is available in the inventory
static bool checkAvailability(Product* product) {
auto it = productMap.find(product->id);
if (it != productMap.end() && it->second.quantity >= product->quantity) {
return true;
}
return false;
}
};
// Initialize static member outside the class
std::unordered_map<std::string, Product> Inventory::productMap;
class Order {
public:
std::string id;
Customer customerInfo;
std::vector<Product*> products; // Multiple products in an order
Status orderStatus; // Track order status like Pending, Shipped, etc.
// Constructor for Order
Order(std::string id, Customer customerInfo)
: id(id), customerInfo(customerInfo), orderStatus(Pending) {}
// Method to add products to the order
void addProduct(std::string id, std::string name, float price, int quantity, int perishOrElec) {
if (perishOrElec == 1) {
std::string expirationDate;
std::cout << "Enter expiration date: ";
std::cin >> expirationDate;
PerishableProduct* perishable = new PerishableProduct(id, name, price, quantity, expirationDate);
products.push_back(perishable);
} else {
int warrantyPeriod;
std::cout << "Enter Warranty Period (in months): ";
std::cin >> warrantyPeriod;
ElectronicProduct* electronic = new ElectronicProduct(id, name, price, quantity, warrantyPeriod);
products.push_back(electronic);
}
}
// Method to check product availability using the static function of Inventory
void setStatus() {
for (auto& p : products) {
if (Inventory::checkAvailability(p)) { // Static call to check availability
std::cout << "Product " << p->name << " is available in the inventory." << std::endl;
orderStatus = Success;
} else {
std::cout << "Product " << p->name << " is not available in the inventory." << std::endl;
orderStatus = Failure;
}
}
}
};
class Shipment {
public:
Order order;
Status shipmentStatus; // Use enum for shipment status
// Constructor and methods to manage shipment
Shipment(Order order, Status shipmentStatus)
: order(order), shipmentStatus(shipmentStatus) {}
void setStatus(){
if(order.orderStatus == Success){
shipmentStatus = Shipped;
}
else{
shipmentStatus = Pending;
}
}
};
class Warehouse {
public:
int capacity;
std::string location;
Inventory inventory; // Manage a single inventory for simplicity
// Constructor for Warehouse
Warehouse(int capacity, std::string location)
: capacity(capacity), location(location) {}
// Initialize the inventory with products
void initializeInventory(const std::vector<Product>& products) {
Inventory::initializeInventory(products); // Use static method to initialize inventory
}
// Process an order and check inventory availability
void processOrder(Order& order) {
order.setStatus(); // Check availability and update order status
}
// Shipment management
void shipOrder(Order& order) {
Shipment shipment(order, Pending); // Create a shipment
shipment.setStatus(); // Set shipment status based on order status
// Print shipment status
if (shipment.shipmentStatus == Shipped) {
std::cout << "Order " << order.id << " has been shipped." << std::endl;
} else {
std::cout << "Order " << order.id << " is pending due to unavailable products." << std::endl;
}
}
};
int main() {
// Create initial products for the inventory
std::vector<Product> initialProducts = {
Product("P001", "Milk", 2.99, 50),
Product("P002", "TV", 399.99, 10),
Product("P003", "Bread", 1.99, 100)
};
// Initialize Warehouse
Warehouse warehouse(100, "New York"); // Capacity: 100, Location: New York
warehouse.initializeInventory(initialProducts); // Initialize the warehouse inventory
// Create a customer
Customer customer("John Doe", "123 Main St", "[email protected]", "123456789");
// Create an order
Order order("O001", customer);
// Add products to the order (using IDs that match the initialized inventory)
order.addProduct("P001", "Milk", 2.99, 5, 1); // Perishable product (Milk)
order.addProduct("P002", "TV", 399.99, 1, 0); // Electronic product (TV)
// Process the order in the warehouse (check availability)
warehouse.processOrder(order);
// Ship the order based on the order status
warehouse.shipOrder(order);
return 0;
}
Adhere to SOLID Guidelines
Check and explain whether your design adheres to solid principles (Ask interviewer what SOLID principle is if you can not recall it.)...
Consider Scalability and Flexibility
Explain how your design can handle changes in scale and whether it would be easily to extend with new functionalities...
Create/Explain your diagram(s)
Try creating a class, flow, state and/or sequence diagram using the diagramming tool. Mermaid flow diagrams can be used to represent system use cases. You can ask the interviewer bot to create a starter diagram if unfamiliar with the tool. Briefly explain your diagrams if necessary...
Future improvements
Critically examine your design for any flaws or areas for future improvement...