What is high level modules and low level modules.?

后端 未结 1 1285
一向
一向 2021-02-07 02:33

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

相关标签:
1条回答
  • 2021-02-07 03:32

    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");
        }
    }
    
    0 讨论(0)
提交回复
热议问题