什么是高级模块和低级模块? [英] What is high level modules and low level modules.?

查看:74
本文介绍了什么是高级模块和低级模块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这与下面的链接完全相同.

I know this is the exact duplicate of below link.

>什么是高级模块"和低级模块" (在依赖倒置原则的背景下)?

但是在阅读之后,我不明白它到底是什么.

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

High level modules are abstract classes and Interfaces ?

推荐答案

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

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);
        }
    }
}

和低级模块之一(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");
    }
}

这篇关于什么是高级模块和低级模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆