Announcement Announcement Module
Collapse
No announcement yet.
Is it the best practice to use separate form object instead of domain classes? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Is it the best practice to use separate form object instead of domain classes?

    Is it the best practice to use separate form object instead of domain classes?
    What is about code duplication? Usually form object mimics all the fields and relationships from the domain object? Is it worth doing so? What are the benefits?
    Can we use domain objects directly for data binding? Are there any use cases to choose which way to go?

    Thank you.

  • #2
    Can we use domain objects directly for data binding? Are there any use cases to choose which way to go?
    Normally you should find in many books and reference documentation a Domain object (An Entity) used throughout the layers. Therefore is easier to find a JSP with a Domain Object. This happen for Spring MVC and Spring Web Flow

    So forget about code duplication.

    Comment


    • #3
      Thank you for your answer.

      But, if I want to keep my domain object clear, do not implement setter methods (probably all entity initialization is done through constructor and domain object only provides getter methods ), and don't provide public default no-arg constructor (I have the protected one for the JPA purpose, already), and not deal with any validation on it (even include Bean Validation annotations)?
      Right now, I'm thinking about extending from my Domain object for the Form object:
      FormObject extends DomainObject
      , and provide missing features for the Form object, so data binding done successfully.

      What do you think?

      Comment


      • #4
        Hello

        Thank you for your answer.
        You're welcome

        But, if I want to keep my domain object clear, do not implement setter methods (probably all entity initialization is done through constructor and domain object only provides getter methods )
        I dont what do you mean with a domain object clear. If you create an object with such restriction
        practically is inmutable (cant be changed or updated once created). Therefore such object has none sense
        to be used in a JSP Form.

        I am confused with the rest of your reply

        Could you expand detailed your requirement to try to work in your way?

        Comment

        Working...
        X