(Entity-Control-Boundary pattern) -> How to deal with two entities?

后端 未结 1 1646
野性不改
野性不改 2020-12-28 09:59

Premise

I\'ve recently read/watched a lot of articles/videos by Java Champion Adam Bien, where he advocates the usage of the ancient but renewed

相关标签:
1条回答
  • 2020-12-28 10:33

    As far as I understand the Design Pattern you are right with what "you got so far".

    To your main question: as in other design pattern you can simply introduce another SuperComponent that is used in some endpoints (or a single, so that it does not get extremely big). That SuperComponent will do the things the correct way: you will use some existing Components if needed so that the performance and code quality do not suffer. What I mean here: you will probably write logic that relates to that specific endpoint that does not care whether it returns Oranges AND Apples, making a single query to DB (if your domain model is able to do that). Using the other components to fetch those fruits and make a union of them is a bad design, no matter what Design Patterns you use (image you will get Avocados later and then you will have to write code / correct bugs in order to get support for the new fruits).

    Now somehow related to your side question (IMHO): ECB is OK for small projects, but for bigger projects, you will probably want a more-layered Structure:

    • a Web layer that just process the requests / the input from the user (I do not like the idea that my EJBs know about HttpRequests and HttpResponses)

    • a multi-layered application model, with a DAO layer (not mandatory for CRUD operations, but for the case you use the same NamedQuery with 5 parameters in multiple EJBs).

    0 讨论(0)
提交回复
热议问题