Determine the different ways the system will be used. This includes main functions the system needs to perform and who will use it.
Based on the requirements and use cases, identify the main objects of the system...
1.Item
Product in the warehouse
Attributes : id, name, type(perishable/non-perishable), price, size, weight, quantity
2.Order
Customer order containing multiple items
Attributes: id, orderDate, status(pending,shipped, delivered, Map
3.Shipment
Represent incoming or outgoing shipment
Attributes: id, type(incoming/outgoing), List
4.StorageLocation
Physical location in the warehouse where the item is stored
Attributes: id, capacity, locationType(shelf, bin etc)
5.User
Individual user uses the system
Attributes: id, username, password(hash), email, phn, role(admin, manager, worker)
Determine how these objects will interact with each other to fulfill the use cases...
Design inheritance trees where applicable to promote code reuse and polymorphism. This step involves identifying common attributes and behaviors that can be abstracted into parent classes...
Consider using design patterns (e.g., Factory, Singleton, Observer, Strategy) that fit the problem...
Factory Pattern:
We can use factory design pattern for Shipment(Incoming/Outgoing) shipment. Instead of creating it via constructor we can have ShipmentFactory which generates appropriate shipment.
public class ShipmentFactory{
public static Shipment createShipment(String type){
if(type == 'incoming') {
return new IncomingShipment();
}else if(type == 'outgoing') {
return new OutgoingShipment();
}
throw new IllegalArguments("Unknown Shipment");
}
Singleton Pattern
We can use this pattern for database creation. It will ensure only one instance of DatabaseConnection got created
public class DatabaseConnection {
private static DatabaseConnection instance;
private DatabaseConnection (){
/* private constructor */
}
public static DatabaseConnection getInstance(){
if ( instance == null){
instance = new DatabaseConnection();
}
return instance;
}
public void connection(){
/* connection logic */
}
}
Observer Pattern:
The observer pattern can be useful when the stock of an item is added/finished then we need to notify the Stock Manager, Administrator
public interface StockObserver {
void update(Item item);
}
public class StockNotifier {
private List<StockObserver> observers = new ArrayList<>();
public void addObserver(StockObserver ob){
observers.add(ob);
}
public void notifyObservers(Item item){
for(StockObserver obs : observers) {
obs.update(item);
}
}
}
Strategy Design:
This pattern will be useful for optimizing the storage location of an item. Different strategies like(size based, turnover based placement) can be done based on warehouse conditions.
public interface StorageStrategy{
void optimize(Item item);
}
public void SizeStrategy implements StorageStrategy{
public void optimize(Item item){
// Logic to optimizing storage based on size
}
}
public void TurnoverStrategy implements StorageStrategy {
public void optimize(Item item){
// Logic to optimizing turnover
}
}
public class StorageOptimizer{
public StorageStrategy storageStrategy;
public StorageOptimizer(StorageStrategy ss){
this.storageStrategy = ss;
}
public void optimize(Item item){
this.storageStrategy.optimize(item);
}
}
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.
public class Car { ... } // ExampleCheck and explain whether your design adheres to solid principles (Ask interviewer what SOLID principle is if you can not recall it.)...
Explain how your design can handle changes in scale and whether it would be easily to extend with new functionalities...
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...
Critically examine your design for any flaws or areas for future improvement...