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 8827179
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:18:51+00:00 2026-06-14T07:18:51+00:00

In my legacy code I have a a concept of attribute/value pairs. Each attribute/value

  • 0

In my legacy code I have a a concept of attribute/value pairs.

Each attribute/value has some arbitrary meaning in my system. So, my interface has the methods getValue() and setValue(). Each of these does some specific business logic based on what the attribute means in my system.

This works pretty well, but I am running into some issues.

The first is my mapping tends to look something like this:

if (name == "name1") return thisAttributeImplementation();

which is ugly and easy to screw up typing…

The second is that these AttributeImplementations need to know the name of their attributes, but they don’t unless I provide it as a static member, or pass it into the constructor, both of which are ugly.

It seems like enums would be a good solution to both of these problems, but I’m having trouble working out the logistics. What should the enums look like in order to associate a string with an object? How should I iterate through the enums to find the appropriate one? How should the objects themselves gain knowledge of the string they’re associated with?

  • 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-06-14T07:18:52+00:00Added an answer on June 14, 2026 at 7:18 am

    Something similar to this works correct?

    public enum Borough {
        MANHATTAN(1),
        THE_BRONX(2),
        BROOKLYN(3),
        QUEENS(4),
        STATEN_ISLAND(5);
    
        private int code;
    
        private Borough(final int aCode) {
            code = aCode;
        }
    
        /**
         * Returns the borough associated with the code, or else null if the code is not that of a valid borough, e.g., 0.
         * 
         * @param aCode
         * @return
         */
        public static Borough findByCode(final int aCode) {
            for (final Borough borough : values()) {
                if (borough.code == aCode) {
                    return borough;
                }
            }
            return null;
        }
    
        /**
         * Returns the borough associated with the string, or else null if the string is not that of a valid borough, e.g., "Westchester".
         * 
         * @param sBorough
         * @return
         */
        public static Borough findByName(final String sBorough) {
    
            for (final Borough borough : values()) {
                if (borough.name().equals(sBorough)) {
                    return borough;
                }
            }
            return null;
        }
    
        public int fromEnumToInt() {
           return mId;
    }
    
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application (Legacy code) that contains interface Icomponent with save() methods and
I have come across some legacy code that has the following type of line:
I have come across some legacy code that has raised all my heckles as
I'm cleaning up some legacy code and I have found methods which explicitly throw
I'm working with some legacy code and have this existing interface: public interface IProcess
I have some legacy code that was used to monitor my applications cpu,memory etc
I have encountered a weird situation while updating/upgrading some legacy code. I have a
In support of some legacy code, I have to read a text file and
I have some legacy C++ code that I am trying to understand a bit
I have been assigned to work on some legacy C++ code in MFC. One

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.