Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3678862
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T03:23:31+00:00 2026-05-19T03:23:31+00:00

I am trying to build an object to represent a ridiculously large form for

  • 0

I am trying to build an object to represent a ridiculously large form for a project I am working on. http://www.flickr.com/photos/namtax/5351091239/

I didnt want to build all the fields into one large object as I didnt think this was a good way to do things, so I have structured the model as so –

One contact object.

  • One work object – linked to the contact one to one.

  • One travel object – linked to the contact one to one.

  • One address object – linked to the contact one to many.

  • One emergency contact object – linked to the contact one to many.

Here is the sample code for one of these relationships – written in CF9 ORM

    property name="work"
             fieldtype="one-to-one"   
             cfc="work"     
             mappedby="contact";

The issue here is that it causes the saveContact function in my controller to be large and code smelly due to all the possible options you can choose in the form. Here is a rough translation of the code

VARIABLES.contact = contactService.getContact(form.iContactId);
contactService.set(contact:contact,argumentCollection:form);
contact = contactService.save(contact);

if(_emergencyContactService.userIsSubmittingAnEmergencyContact(form)){
  VARIABLES.emergencyContact = _emergencyContactService.getEmergencyContact(contact);

   emergencyContactService.setEmergencyContact(emergencyContact,form);

        if(! contact.hasEmergencyContact()){
            contact.setEmergencyContact(emergencyContact);
            emergencyContact.addarrContacts(contact);
        }

        _emergencyContactService.save(emergencyContact);
    }
// Repeat this logic to check if work object, travel object or address object have been selected in the form also, get and set accordingly.

I then repeat the if statement shown above for emergency contact, to check whether the work object, travel object or address object have been selected in the form also. If so, get and set the object, then link the contact object where necessary.

This doesnt seem efficient to me, especially as I need to repeat all this logic on another controller method as well. Is there a better way to structure my objects, or a better way to handle my controller code?

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T03:23:31+00:00Added an answer on May 19, 2026 at 3:23 am

    My initial thoughts are to move any repeating logic from your controller to a service object that you can call from many places.

    Bringing that along: you could break up the form into sub-forms – each represented by a ‘sub-form’ object. Each of these objects should be able to deal with information related to it’s part of the form, and it should know what to save to the database. You could compose these form objects into a service object that you call from your controller.

    One other thing I noticed is the way you actually pass your entire FORM scope into some functions. I tend to avoid this as you really are not describing what the function needs to do the job, and of course this scope can change when you don’t expect it. I would suggest you specify the arguments required by each sub-form object and pass them to the service.

    Example psuedocode:

    // Controller code
    travelSubFrm = new TravelForm(name, dob, address ...); // etc
    workSubFrm = new WorkForm(position, dept ...); // etc
    
    // Create service and save details - the service knows the logic
    contactFormService.setTravelSubFrm(travelSubFrm);
    contactFormService.setWorkSubFrm(workSubFrm);
    contactFormService.process();
    

    Just some quick thoughts.

    Hope that helps!

    EDIT: If you want to start looking into how to architect object-orientated code then I suggest you check out Head First Design Patterns. It’s a great introduction to the topic and will help you organise code problem like the one you posted.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to build an object through an attribute on a classes property
Trying to build Android open source project on Ubuntu 10.04 (on VMware Player). I
Trying to build a GUI application in Java/Swing. I'm mainly used to painting GUIs
I trying to build and compile my xcodeproj in command line and it is
I'm trying to build a grammar with the following: NUMERIC: INTEGER | FLOAT |
I'm currently trying to build a personal website to create a presence on the
I am trying to build a function in C/C++ to sort an array and
I am trying to build an website for my college's magazine. I used the
I am trying to build out a useful 3d game engine out of the
I am trying to build a dependency graph of tables based on the foreign

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.