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 ?
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.
The class which is performing a task with the help of other class is a High-level class and the class which receives command or helps high-level class to perform a task is often regarded as a Low-level class.
The high-level modules describe those operations in our application that have more abstract nature and contain more complex logic. These modules orchestrate low-level modules in our application. The low-level modules contain more specific individual components focusing on details and smaller parts of the application.
Dependency Inversion Principle states that, higher level modules shouldn't depend on the lower level modules, they should both depend on abstractions. In other words all entities should be based on Abstract Interfaces and not on Concrete Types. The principle also stressed that abstractions should not depend on details.
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"); } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With