2
2
.
.
2
2
O
O
b
b
j
j
e
e
c
c
t
t
T
T
y
y
p
p
e
e
s
s
I
I
n
n
f
f
o
o
Following tutorials explain main terms related to data flow like Objects that are used to
store data: Entity (DO), Command (DTO) (thick border)
transfer data: Repository (DAO), Controller (CO) (thin border)
convert data: Converter (DCO) (thin border)
Below schema shows three main parts of the Web Application that work together
front-end application might be Web Browser or Mobile Application (colored in blue)
back-end application is what we are building with Spring Boot (colored in gray)
database application is used to store data (colored in red)
Back-end application
works with Entity (DO) Objects (each represents a record in the DB)
doesn't work with DB Tables
doesn't know where data comes from: DB, File, URL, Array, ...
When back-end needs
to get data from DB it calls method from Repository (DAO) which returns Entity (DO) Object with retrieved data
to store data into DB it calls method from Repository (DAO) and provides Entity (DO) Object with data to be stored
to send data to Frontend it stores data in Command (DTO) Object and sends that
In the process it uses Controller (CO) to convert Entity (DO) Object into Command (DTO) Object
Relations between Objects
BACK-END
DATABASE
FRONT-END
HOLD
DATA
COMMUNICATION
METHODS
CONVERSION
METHODS
Converter (DCO)
Data Converter Object
Entity (DO)
Data Object
Command (DTO)
Data Transfer Object
Repository (DAO)
Data Access Object
Controller (CO)
Controller Object
Terms
NAME
DESCRIPTION
Entity (DO)
Data Object
Entity Object represents record in DB Table and contains
Properties (that are equivalent to DB Table Columns)
Helper Methods (setters, getters, equals, toString)
Command (DTO)
Data Transfer Object
Command Object is used to transfer data between application layers and contains
Properties (subset of Entity properties)
Helper Methods (setters, getters, equals, toString)
Repository (DAO)
Data Access Object
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)
Controller (CO)
Controller Object
Controller Object contains
Methods that accept HTTP Requests (end points)
Converter (DCO)
Data Converter Object
Converter Object contains
Methods for converting between Command (DTO) and Entity (DO) Objects
A
A
p
p
p
p
l
l
i
i
c
c
a
a
t
t
i
i
o
o
n
n
S
S
t
t
r
r
u
u
c
c
t
t
u
u
r
r
e
e
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
Application Schema
Controller
Service Layer
DTO
DTO
DTO
DTO
Repositories
Entity
Entity
Entity
Entity
HTTP
Response
HTTP
Request
SQL
Data
COMMUNICATION WITH
FRONT END
COMMUNICATION WITH
DATABASE
BUSSINESS
LOGIC
BACK END