Based on the requirements and use cases, identify the main objects of the system...
Stock (cargoId, availability)
Order (id, cargoId, number, placedTimestamp, status)
Cargo (id, price, size)
Shipment (orderId, status, estimatedDelivery)
LocationOptimizor (arrange functino)
Stock is a singleton, have multiple cargos
Each Order has one Cargo
Each Shipment has multiple Orders
LocationOptimizor is a singleton, arrange cargo storage location based on its size.
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...
Shipment is an interface which is implemented by InShipment and OutShipment.
Consider using design patterns (e.g., Factory, Singleton, Observer, Strategy) that fit the problem...
Stock is a singleton. LocationOptimizor is a singleton.
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.
Inventory (cargoId, availability)
Order (id, cargoId, number, placedTimestamp, status)
Cargo (id, price, size)
Shipment (orderId, status, estimatedDelivery)
LocationOptimizor (arrange functino)
sealed class CargoSize (val size: Int) {
object SMALL : CargoSize(4)
object MEDIUM : CargoSize(8)
object LARGE : CargoSize(12)
}
class Cargo(val id: Int, val price: Double, val size: CargoSize)
object LocationOptimizor {
optimize(cargos: MutableMap<Int, Int>, capacities: MutableMap<Int, Int>){
}
}
object Inventory(val availabilities: MutableMap<Int, Int>,
val capacities: MutableMap<Int, Int>, // position/spot (Int id) to size (Int)
val locationOptimizor: LocationOptimizor){
fun add(cargo: Cargo, number: Int)
fun remove(cargo: Cargo, number: Int)
fun checkAvailability(cargo: Cargo)
fun optimizeLocation() {
locationOptimizor.optimize(availabilities, capacities)
}
}
object OrderManager() {
fun persistOrder(order: Order)
fun getOrder(orderId: Int)
}
class Order(val id: Int, val cargo: Cargo, val number: Int) {
fun place()
}
class IncomingOrder(val id: Int, val cargo: Cargo, val number: Int) : Order(id: Int, cargo: Cargo, number: Int){
fun place(){
Inventory.add(cargo, number)
}
}
class outgoingOrder(val id: Int, val cargo: Cargo, val number: Int) : Order(id: Int, cargo: Cargo, number: Int){
fun place(){
Inventory.remove(cargo, number)
}
}
enum class ShipmentStatus{
PROCESSING,
SHIPPED,
DELIVERED
}
class Shipment(val id: Int, val order: Order, val status: ShipmentStatus) {
fun addOrder(val order: Order)
fun removeOrder(val order: Order)
}
Check 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...