Results 1 to 4 of 4

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

  1. #1
    Join Date
    Mar 2008
    Posts
    29

    Lightbulb 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. #2
    Join Date
    Aug 2006
    Location
    Arequipa-Peru / South America
    Posts
    2,796

    Default

    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.
    - Manuel Jordan

    Kill Your Pride, Share Your Knowledge With All
    The Fear Of The LORD Is The Beginning Of Knowledge, But Fools Despise Wisdom And Discipline. Proverbs 1:7

    Blog


    Technical Reviewer of Apress

    • Pro SpringSource dm Server
    • Spring Enterprise Recipes: A Problem-Solution Approach
    • Spring Recipes: A Problem-Solution Approach, 2nd Edition
    • Pro Spring Integration
    • Pro Spring Batch
    • Pro Spring 3
    • Pro Spring MVC: With Web Flow
    • Pro Spring Security

  3. #3
    Join Date
    Mar 2008
    Posts
    29

    Default

    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?

  4. #4
    Join Date
    Aug 2006
    Location
    Arequipa-Peru / South America
    Posts
    2,796

    Default

    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?
    - Manuel Jordan

    Kill Your Pride, Share Your Knowledge With All
    The Fear Of The LORD Is The Beginning Of Knowledge, But Fools Despise Wisdom And Discipline. Proverbs 1:7

    Blog


    Technical Reviewer of Apress

    • Pro SpringSource dm Server
    • Spring Enterprise Recipes: A Problem-Solution Approach
    • Spring Recipes: A Problem-Solution Approach, 2nd Edition
    • Pro Spring Integration
    • Pro Spring Batch
    • Pro Spring 3
    • Pro Spring MVC: With Web Flow
    • Pro Spring Security

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •