How to use Struts ActionForms, Value Objects and Entities?

I have inherited a large Java application that uses Struts, Spring, and Hibernate. The classes and interfaces that I do daily are: Struts Actions, Struts ActionForms, Value objects, interfaces and service implementations, DAO interfaces and implementations, and entities. I understand quite clearly how and why most of them, except that I'm not sure about the correct separation of duties between ActionForms, Value Objects and Entities. It should also be mentioned that the domain model (i.e., All entities) does not contain significant (if any) real business logic. This is essentially a CRUD application, and most of the real logic is in the database (yuck!). Anyway, there are several different Java-related issues that I'm interested in:

1) It seems that there is not much difference between the objects and the Value (VO) objects, and a lot of code should be written to convert to another when they pass through the service level in any direction (Struts Actions concern only VO, DAO deal only with Entities) . Thus, VO and Essences seem somewhat redundant. Why are they both?

2) Where should the VO ↔ Entity translation code be? Service Level, Entity, VO?

3) VOs are placed directly in ActionForms and are directly related to tags in JSP (for example,). Is this a good practice? If not, what design?

4) It is not clear how to properly handle foreign key dependencies in Value objects. For example, some VOs have a type field, which in terms of a database represents a foreign key relationship in a type table. In the user interface, this translates into a drop-down field that allows the user to select a type, or label, that simply displays a textual representation of the type (depending on which screen it is on). Now, if VO has a property for a type identifier, a text representation of a type, or both? Who is responsible for the translation between them and when?

5) The OB has a field for the database identifier. I thought OV has no credentials? What's up with that?

I hope that these questions are general enough to be of general interest. It seems to have been appearing all this time in this type of architecture.

, , , , . , - , .

+3
3

1. DAO-VO; , , Hibernate. - Hibernate, VO.

, , DAO , DAO, . , , , .

, , VO , .

3. VO ; VO JSP, , ? , , ( ).

1. DAO , , JSP, DAO .

  1. , , id . DAO VO DAO, , , DAO VO:)

  2. - . , , , -, .

, VO , :

  • id
  • VO VO

- , . , - , . , .

, VO id. . String , - ( ) VO. , , .

; DAO-VO, , . Hibernate - , . , . , , , .

; DAO-VO - - EJB2 Hibernate. , , , , .

+3

1) VO Entities: ​​ . , , , , ( )

2) : DAO Action, ?

3) , , ​​DAO

4) .

5), , ?

, . .

+1

, Spring MVC Struts. - , , Hibernate -.

For example, in an application that I used using Spring MVC, I had a member class. Logging in, registering, changing the password and editing all profile forms were tied to this class. The class also had a sleep mode display and a good part of the business logic inside (for example, for a social network - the “add a friend” method).

0
source

Source: https://habr.com/ru/post/1697859/


All Articles