Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is high level modules and low level modules.?

Tags:

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 ? 
like image 688
Sahal Avatar asked May 15 '13 06:05

Sahal


People also ask

What is high level module in programming?

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.

What are high level and low-level classes?

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.

What is high level modules in C#?

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.

Why high level modules should not depend on low-level modules?

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.


1 Answers

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");     } } 
like image 149
Fendy Avatar answered Dec 12 '22 00:12

Fendy