I support the ASP.NET MVC project. In the project, the original developer has an absolute ton of interfaces. For example: IOrderService , IPaymentService , IEmailService , IResourceService . What I'm embarrassed about is that each of them is implemented by only one class. In other words:
OrderService : IOrderService PaymentService : IPaymentService
My understanding of interfaces has always been that they are used to create an architecture in which components can be easily changed. Sort of:
Square : IShape Circle : IShape
In addition, I do not understand how they are created and used. Here is the OrderService:
public class OrderService : IOrderService { private readonly ICommunicationService _communicationService; private readonly ILogger _logger; private readonly IRepository<Product> _productRepository; public OrderService(ICommunicationService communicationService, ILogger logger, IRepository<Product> productRepository) { _communicationService = communicationService; _logger = logger; _productRepository = productRepository; } }
These objects never seem to be created directly, since in OrderService orderService = new OrderService() it always uses an interface. I don’t understand why the interfaces are used instead of the class that implements the interface, or how it works. Is there anything important that I am missing in the interfaces, that my Google skills are not being revealed?
source share