Entity Object represents record in DB Table and contains
● Properties (that are equivalent to DB Table Columns)
● Helper Methods (setters, getters, equals, toString)
Command Object is used to transfer data between application layers and contains
● Properties (subset of Entity properties)
● Helper Methods (setters, getters, equals, toString)
Repository Object is used to store/retrieve Entities into/from DB and contains
● Entity Property (that holds data)
● Methods for accessing DB (for storing and retrieving data)
Main part of any Application is Service Layer which consists of Service Objects which implement Business Logic.
Every other part of the application is just plumbing allowing Service Objects to perform their tasks
● On one side we have Presentation Layer which allows Service Layer to communicate with outside world
● On the other side we have Persistence Layer which allows Service Layer to memorize things (persist them in DB)
Service Layer uses
● Data Transfer Objects (DTO) to encapsulate data that is exchanged with Presentation Layer
● Entities to encapsulate data that is exchanged with Persistence Layer
Since the above Data Objects just hold pure data (without any methods/logic) Service Layer uses
● Controller to communicate with Presentation Layer (can be only one)
● Repositories to communicate with Persistence Layer (one for every Entity)
Controller
● receives HTTP Request
● creates DTO from the data in HTTP Request
● forwards DTO to specific Service Object (that is mapped to that type of HTTP Request)
● receives DTO returned by the Service Object
● forwards returned DTO back to the front-end (as the final response to the HTTP Request)
Service Object
● receives DTO from the Controller
● creates Entities from DTO
● performs CRUD Requests toward Persistence Layer (Create Read Update Delete Entities)
● performs its business logic using Entities (those from DTO and those from Persistence Layer)
● creates DTO from Entities
● returns DTO back to the Controller