mercredi 20 novembre 2019

pattern for JPA Entity facilitator methods

What data structure pattern should be used along with JPA for writing facilitator methods?

I'm using Hibernate JPA and have almost 2 dozen @Entity. Current structure of my application is

| Controller Layer | --> | Service Layer | --> | Data Access Layer |

My service layer has lots of business rules. Dummy E.g. Employee entity has manager column variable. Business Rule is he/she is a manager if MANAGER column is having NULL value. Else he/she is reporting to some manager.

As part of single responsibility principle I would go and write a method in Employee entity which will return boolean.

public boolean isManager() { return this.manager == null; }

My problem is I need half a dozen such facilitator methods in Entity. Should I write it in Enity or should I consider any other pattern for that? which pattern should I try for such case?

PS: based on the facilitator methods(business rules) i want to use entities for persisting back or other crud operations.

Aucun commentaire:

Enregistrer un commentaire