Which template fits between the facade and the DAO?

I am developing a piece of my company's architecture for my Java EE web applications. I explain quite clearly the reasons for using a facade and one or more DAOs. I have a problem:

There will be a certain logic, which definitely belongs to the level of integration, because all this concerns the coordination of the data model. In addition, the logic goes beyond simply maintaining referential integrity and other raw storage tasks that will be handled by JPA and Hibernate. I do not classify this as business logic because it is separate from any business function. However, I understand that a DAO should only implement the logic needed to access and store objects in a data source.

My conclusion is that I need a business object template that is suitable for the integration level. I looked around, and the closest I found (but still not quite right) is the Sun Transfer Object Assembler Template .

Is there a gap in my understanding of Java EE or is there a pattern that will fit.

+6
java java-ee design-patterns
source share
5 answers

maybe a mediator is what you want:

Define an object that encapsulates how a collection of objects interacts. The mediator promotes free connection, preventing direct access of objects to each other, and allows you to independently change their interaction.

then you can use the DaoMediator to coordinate two or more DAO

+4
source share

It sounds as if you might not have a controller, and therefore, you might need an MVC pattern . The controller will monitor the DAO and present a consistent view (do not think in terms of graphical interfaces, most likely using a client-oriented interface). When changes are made using this view, then the controller coordinates the changes to the model using the DAO. I suspect that your façade features might be view in this scenario.

Having said that, I would not worry too much about identifying specific models. You often find that, taking into account all your requirements and sharing problems, where applicable, you will eventually implement a specific model and only identify it as such after this fact.

+2
source share

Have you considered using aggregates from Domain Driven Design? I myself participate in DDD, and it looks like the business logic you are trying to design can be achieved thanks to the richer POJO-like domain models. You will have each domain object to be responsible for its aggregate objects, and also include any logic regarding this business concept; that your level of integration will coordinate these rich objects, but will refrain from real logic as such (i.e. several conditional logics).

Perhaps the pattern you are trying to find is actually a step towards richer domain objects?

+1
source share

I think this is a DataMapper (or Adapter) template between your DAL and your business layer, but without a more specific understanding, I could not be sure.

0
source share

What is the requirement for consistency between DAOs? If there is any business assumption that dictates the relationship. For example, you may have an account type, which when it is “Capital”, then we need to make sure that several other objects are in the correct state or have the correct set of values. This definitely goes beyond the data layer.

I would not try to find the perfect sample for this occasion. You need some kind of coordinating class, albeit a mediator or controller.

0
source share

All Articles