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

  • SEARCH
  • Home
  • 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 6573007
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:04:39+00:00 2026-05-25T15:04:39+00:00

I’ve the following scenario. My application interacts with the database which contains some static

  • 0

I’ve the following scenario. My application interacts with the database which contains some static tables. If I have to use that static information in the code level mostly for conditional code, what is the best approach.

For eg: I’ve a student database, which contains a static table student_type ( indicating hard-working, smart, lazy etc types ). In the code, I need to take action based on the student_type.

So, my code would look like this

studentTypeId = student.getTypeId(); // student constructed from database
switch (studentTypeId)
{
    case HARDWORKING_ID :
       // do something
    case LAZY_ID :
       // do something
    break;
}

Well, in my code, I would either use constants or an enum to store type ids. But, isn’t this kind of replicating things in code since I already have type ids in database. If the type id in database changes I’ll have to change the same in my Enum which increases maintenance. Is there a better way to achieve this?

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-25T15:04:40+00:00Added an answer on May 25, 2026 at 3:04 pm

    The question to ask is: does the addition of the row in the database imply a change in your java? If yes, go for the enum approach, and don’t worry about the duplication. If you’re going to have to change code anyway, for instance, to add new cases to your switch, then I usually find it’s a good idea to keep things simple.

    studentTypeId = student.getTypeId(); // student constructed from database
    switch (studentTypeId)
    {
        case HARDWORKING_ID :
           // do something
        case LAZY_ID :
           // do something
        case SMART_ID :     // added smart student, very rare corner case :-)
           // do something
        break;
    }
    

    Often in cases where you’re storing static data like this you’ve got other constraints that go with the data, and when you change the data in the database, you have to change the code that uses that data.

    If you really really want to reduce the duplication, then you can go for a fully pluggable architecture, as suggested by Dave Newton. This could be implemented as a id -> class name relation for each id. You’d then instantiate the class and all of the logic associated with each id would be contained in that class. This isn’t always easy or possible. For your example, it may well be possible, but unless it’s done right, this can be complicated.

    Also, it doesn’t solve all of your problems. You still have to develop the java, test it, and redeploy the new class. So actually, the amount of work you would save may be minimal.

    It’s often easier to accept the small amount of duplication and just go with the simple solution.

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

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I have a reasonable size flat file database of text documents mostly saved in
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.