Pergunta

I'm creating a 3-tiers application, and I encountered a problem.
I have a database that holds data about customers and a class that represents a customer entity in my app. The problem is, I don't know if I should instantiate a customer entity in the Data tier or in the Application tier.

Creating the customer entity in the Application tier seems more correct, because the Data tier is supposed to only query the data, but this would mean that I need to use "raw/unformatted" data in the Application tier and that don't look good either.

Anyone know the "correct" way to deal with this ?

Foi útil?

Solução

Database persists state and before it can be queried that sate must be saved. A new Customer entity is instantiated by the Application then sent to Persistance to be saved. When the application needs a certain Customer from the db, the Persistence (usually the Repository) restores the Customer.

Note that the Customer is a Business entity, related but not the same with a Customer table or a Customer ORM entity which is simply a data structure modeled from the database point of view to be optimized for queries.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top