我知道这是以下链接的完全相同的副本。
What are "High-level modules" and "low-level modules" (in the context of Dependency inversion principle)?
但是读完之后我不明白它到底是什么。
High level modules are abstract classes and Interfaces ?
最佳答案
高级模块是将由表示层直接使用的接口(interface)/抽象。另一方面,低层是一堆小模块(子系统)帮助高层完成他们的工作。下面的示例是高级模块。我已经排除了较短样本的依赖构造函数注入(inject)。
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");
}
}
关于oop - 什么是高级模块和低级模块。?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16558256/