Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat design patterns fit this code smell?
    text
    copied!<p>I have a PDF form that has 450 fields in it and I'm going to fill it out using data that is in my Database. Each field in the PDF has a unique name and I can do a mapping like:</p> <pre><code>switch (fieldname) { case "Name": value = GetData(Name); break; // Etc... case "Date": value = Date(); break; default: value = ""; break; } </code></pre> <p>Now it seems like this is going to get very complex fast having 450 branches and if other documents get added it could grow massively. What are the potential patterns that are available to solve this kind of problem? Essentially I want to bind the PDF fields to the Database fields.</p> <p><em><strong></em>* EDIT <em>*</em></strong> So lets just say that I have a giant switch statement ~450 branches, that routes PDF field names like 'Name' 'Address' 'Phone' to the correct database query for execution. What other ways can I solve this other than switching on the field names when the field names are variable depending on which document was selected by the end user.</p> <p><em><strong></em>* FINAL EDIT <em>*</em></strong> I thought about it for a day and came up with solution thanks to all the suggestions. I have a function called GetElement(). It takes the PDF field name as a parameter and executes a stored procedure that returns the database column and another procedure name as a map. Then using some dynamic SQL I pass the procedure name and column i'm looking for and return the results. Hard to pick the right answer here but I'll give credit to the one that pushed me the closest.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload