I know this is the exact duplicate of below link.
What are "High-level modules" and "low-level modules" (in the context of Dependency inversion prin
High level module is the interface / abstraction that will be consumed directly by the presentation layer. Low level on the other hand are bunch of small modules (subsystems) help the high level do their work. Example below is the high level module. I have excluded the dependency constructor injection for shorter sample.
public class OrderService : IOrderService
{
public void InsertOrder(Order ord)
{
if(orderValidator.IsValidOrder(ord)
{
orderRepository.InsertNew(ord);
userNotification.Notify(ord);
}
}
}
And one of the low level module (the OrderValidator
):
public class OrderValidator : IOrderValidator
{
public bool IsValidOrder(Order ord)
{
if(ord == null)
throw new NullArgumentException("Order is null");
else if(string.IsNullOrEmpty(ord.CustomerId))
throw new InvalidArgumentException("Customer is not set");
else if(ord.Details == null || !ord.Details.Any())
throw new InvalidArgumentException("Order detail is empty");
}
}