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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:40:27+00:00 2026-05-22T01:40:27+00:00

In a application data entry, I allow the user to insert a numeric value

  • 0

In a application data entry, I allow the user to insert a numeric value that can represent two different things:

  1. an absolute value, say 5, meaning that a property P should be assigned the value 5
  2. a relative value, say +5, meaning that the property P should be incremented by 5

My question is: which data-structure use to store this inforation?
I lay down some alternatives.
My idea is going with the 3rd idea, but I wonder is the pattern is “correct”.

1)
Here the absolute xor the increment is assigned, the other left null. Not very satisfactory.

class DoubleFieldBased {
    Integer absolute;
    Integer increment; 
} 

2)
Here the “magnitude” of the value is saved into “value”, while the boolean “increment” tells wheter the value is absolute or relative. Even less satisfactory.

class FieldAndBoolean {
    Integer value;
    boolean increment;
}

3)Here I move the focus to the method applyValue, that uses polymorphism and do the right thing based on the implicit information of what class “am I”. Satisfactory but a bit complex, and I suspect the pattern isn’t perfect.

public static abstract class AbstractValue {
    int myvalue;
    public AbstractValue (int myvalue) {this.myvalue = myvalue;}
    public abstract int applyValue (int value);
}

public static class Absolute extends AbstractValue {
    public Absolute (int myvalue) {super(myvalue);}
    public int applyValue (int value) {
        return value;
    }
}

public static class Incremental extends AbstractValue {
    public Incremental (int myvalue) {super(myvalue);}
    public int applyValue(int value) {
        return myvalue + value;
    }
}
  • 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-22T01:40:28+00:00Added an answer on May 22, 2026 at 1:40 am

    I’d say use an Integer or other numeric type) and an enum, something like this:

    enum Type{
    ABSOLUTE, INCREMENT, PERCENTAGE /* etc */
    }
    
    public class Value{
        int /* or float */ numericValue;
        Type type;
    }
    

    You could even use the enum as strategy:

    enum Type{
      ABSOLUTE{
          public int apply(int newValue, int oldValue){return newValue;}
      }, INCREMENT{
          public int apply(int newValue, int oldValue){return oldValue + newValue;}
      } /* etc */
      ;
      public abstract int apply(int newValue, int oldValue);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose that you have a big Data Entry Web Application Like Microsoft CRM ,
I have a data entry form in a HTML5 application that users will be
I'm working on an asp.net application that allows the user to update data for
I have a data entry application, with (among other things) a textbox for recording
i have four differnet data entry users that will be using four different forms
I've got an asp.net application where each client will have their own data entry
I am currently building an application using ASP.NET MVC. The data entry pages are
Possible Duplicate: VS2008 Setup Project: Shared (By All Users) Application Data Files? Please can
I know that we shouldn't being using the registry to store Application Data anymore,
I am in the process of designing an application that will allow you to

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.