简体   繁体   中英

Java Architecture 3 tier object design

This is a Spring Boot API project. We currently have a 3 phase model design and I wanted to know if that is enterprise best practice. For example, if someone made a GET call for all cars then the API would:

  1. Call the DB to get all the cars and store them in CarEntity . This contains some db information like date added, updated date, etc
  2. Would pass the entity to the business layer after converting to a Car object. This strips off that extra db info.
  3. Would pass the Car object to the control to be sent to the client after converting to a CarDTO object.

So for 1 general type we have 3 objects: CarEntity , Car , CarDTO . Is this the most efficient and best practice?

It really depends on your requirements and design needs.

I design simple web applications and generally use the same object across all three layers (Persistence, Business and Web).

But in some cases you would need more than one class. For instance, if you expose a class for a remote client, it'd make sense to create a new class instead of reusing the persistence layer class.

In the EE world, they like to stress Separation of Concerns and SOLID pricipals . So, you could argue that multiple objects are most efficient and best practice in the long run. For my use, they are generally winded and clutter the project. In some cases, they are necessary.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM