Introduction

Sometimes we need to develop a web service that provides CRUD (Create, Read, Update, and Delete) operations for an entity that supports inheritance. However, the traditional layered architecture (controller layer, service layer, and repository layer) is not enough to have a clean and scalable code. Indeed, if we put the business logic and mapping code inside the service layer, we will have two main problems:

Having multiple conditions based on the DTO class type
Each time we want to introduce a new subclass, we need to modify the service layer, which is not good if we are developing a framework.

The code below illustrates what the service class will look like if we use the traditional architecture:

Top
Generated by Feedzy