Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Domain layer and the persistence layer difference

Does the domain layer and the persistence layer refer to same or are they different. Domain layer is the DAO's which we usually map to database tables right? so does persistence layer means the same or is there more?

And if we are calling the POJO's which map to database tables as DAO's, what we say the classes which resides the execution of queries and populate those DAO's (POJOS).

What is the best practice? Keeping the query execution code inside those POJO's or make them a separate class? i mean example suppose A is the class map to database table A. Do we need to implement separate class like ADaoImpl for place the query related code need for class A? i belive its not right? isnt it the best practice keep all the DAO objects populating, query executions etc related to all DAO classes in a single class called something RDBMSDaoImpl. so we called that class a DAO Implementation class of out application which belongs to the DAO layer right?

So as a summary the POJOS(DAO) and DAOImpl is the DAO layer of our application right? and the persistence layer is..?

Thanks.

like image 888
Harshana Avatar asked Nov 24 '11 07:11

Harshana


People also ask

What is a persistence layer?

In Java servers, persistence layer is also known as the repository layer. This layer is responsible for data persistence and is used by the business layer to access the cache and database. In terms of functionality, it is fine to write the persistence layer code in the service class.

What is the domain layer?

The domain layer is an optional layer that sits between the UI layer and the data layer. Figure 1. The domain layer's role in app architecture. The domain layer is responsible for encapsulating complex business logic, or simple business logic that is reused by multiple ViewModels.

What is Domain persistence?

A domain model should always be concerned with domain BEHAVIOR, while a persistence model, at most, it stores domain object STATE. The persistence models what you want to store from an object and that data will be used to restore the object.

What is service layer and persistence layer?

The persistence layer saves and retrieves your model data. The service layer is a buffer between your application and persistence layers: having it lets you swap out your persistence layer for a different implementation without modifying anything but the calls in the service layer.


2 Answers

Wikipedia: "A business logic layer (BLL), also known as the domain layer". So that's you service layer, where you perform your business logic. The persistence layer is responsible for manipulating the database, and it is used by the service layer.

(Btw, I would prefer "service layer" instead of "domain layer" in an anemic application - that is, an application with stateless, fat services and domain objects with only getters and setters.)

like image 196
Bozho Avatar answered Oct 03 '22 20:10

Bozho


The domain layer is where you model your objects and application features. If you are building an Invoicing application the domain layer should contain the Invoice, Vat and InvoiceItem objects for example. The DAO layer is responsible for retrieving and saving objects from your storage (RDMS database, NoSQL database, etc). In your code, you could have something like

public InvoiceDao {
    public void insert(Invoice invoice) {
    //use your database api to insert invoice
    }
}
like image 30
Giovanni Avatar answered Oct 03 '22 21:10

Giovanni