What is high level modules and low level modules.?

2019-04-20 02:54发布

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 principle)?

But after reading that I do not understand what exactly it is.

High level modules are abstract classes and Interfaces ?

1条回答
你好瞎i
2楼-- · 2019-04-20 03:58

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");
    }
}
查看更多
登录 后发表回答