【问题标题】:What is high level modules and low level modules.?什么是高级模块和低级模块。?
【发布时间】:2013-05-09 14:58:33
【问题描述】:

我知道这是以下链接的完全相同的副本。

What are "High-level modules" and "low-level modules" (in the context of Dependency inversion principle)?

但是读完之后我不明白它到底是什么。

High level modules are abstract classes and Interfaces ?

【问题讨论】:

    标签: oop language-agnostic dependencies


    【解决方案1】:

    高级模块是表示层直接使用的接口/抽象。另一方面,低层是一堆小模块(子系统)帮助高层完成他们的工作。下面的示例是高级模块。我已经排除了较短示例的依赖构造函数注入。

    public class OrderService : IOrderService
    {
        public void InsertOrder(Order ord)
        {
            if(orderValidator.IsValidOrder(ord)
            {
                orderRepository.InsertNew(ord);
                userNotification.Notify(ord);
            }
        }
    }
    

    还有一个低级模块(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");
        }
    }
    

    【讨论】:

    • High level module is the interface / abstraction that will be consumed directly by the presentation layer.,如果没有表现层怎么办?有时关系只是两个类之间的关系,那么哪个类成为高级,哪个成为低级?
    猜你喜欢
    • 1970-01-01
    • 2011-04-16
    • 1970-01-01
    • 2017-09-22
    • 1970-01-01
    • 2023-03-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多