Search code examples
c#javan-tier-architecturebusiness-logic

Where should I put custom attributes for my objects? In the POJO/POCO class or the service layer?


This question was for a Java project I'm working on but could apply to C# too.

Anyway, so I have an MVC web project. In it, I have three "layers" for my data.

com.example.model.dao
com.example.model.entities
com.example.model.service

So dao is my low-level database classes. Things like Hibernate wrappers, etc. entities are my POJO's and service is my business logic.

Now let's say one of those POJO's is User. In User, it maps to a database table called users. This table (and POJO) has two fields, firstname and lastname. OK, so I want to put a method somewhere called getFullName that simply concatenates the first and last name.

So where should this method go? I thought about putting it in the POJO itself. But since sometimes we use tools to generate POJO's from a database, custom logic there could be overwritten. And is this a business process anyway?

Should I put it in my service implementation?

Thanks for your suggestions.


Solution

  • You should implement custom business logic in the business layer. In this case it should be in your service layer as you are generating your POJOs.