This was asked of me at an Interview and feedback I got was I lack OOD skills. So I want to know what is wrong with my suggested design.
Problem Statement: Design a system which helps calculate the TotalCost of the items in the Cart. You will be given a list of items in the Cart with Discounts like in the example below. The list would contain either items or discounts and the sequence matters:
Sample cart: $10 Book xyz, 10% Discount on all items, $20 stationary, 20% discount on next item, $100 Shirt, $15 off on 5th Item of Type Book.
Types of Discounts: 10% Discount on all items 20% discount on next item $15 off on 5th Item of Type Book (More type of Discounts can be added later to the system)
Solution I gave:
Here is the Class Diagram I made:
Here is the TotalCost() Algorithm:
public decimal TotalCost(List<CartItem> cartItems)
{
var totalCost =0.0;
var items = cartItems.where(c => c.Item!=null).Select(c.Item);
foreach(var cartItem in cartItems)
{
if(cartItem.Coupon != Null)
{
cartItem.CouponType.CalculateDiscounts(items);
}
}
foreach(var item in items)
{
totalCost += item.DiscountedCost;
}
return totalCost;
}
Aucun commentaire:
Enregistrer un commentaire