0

I've built a Java application for, globally, mange computers database at my job. At first, I've been told that we needed a tab called 'Users', which would contain first name, last name and email. But now, the technician wants to add other fields such as address, phone, etc. He asked me if he could add himself these fields. The problem is, he's not a programmer. He wants to add these fields with a GUI. I have built the application with static fields, and here is my User Class.

public class User {

    private String firstname;
    private String lastname;
    private String email;
    private int id;

    public User(String firstname, String lastname) {
        this.firstname = firstname;
        this.lastname = lastname;
    }

    public User(int id, String firstname, String lastname, String email) {
        this.id = id;
        this.firstname = firstname;
        this.lastname = lastname;
        this.email = email;
    }

    public User(String firstname, String lastname, String email) {
        this.firstname = firstname;
        this.lastname = lastname;
        this.email = email;
    }

    public String getFirstname() {
        return firstname;
    }

    public void setFirstname(String firstname) {
        this.firstname = firstname;
    }

    public String getLastname() {
        return lastname;
    }

    public void setLastname(String lastname) {
        this.lastname = lastname;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public int getId() {
        return id;
    }

    public String toString() {
        return firstname + " " + lastname;
    }
}

Now, I wonder if there's a way to modify this class using the GUI or if I have to rebuild entirely the software and stop using object classes like that. There are also classes like "Software" and "Operating Systems" that have static fields but need to be modified if necessary.

I don't know what options exactly I have to get the job done:

  • Let the tech modify the database and do something like "for each column in database, add this column in the GUI". (Which would cause to rebuild the entire software.)

  • others?

Any reads/tutorials on that kind of issues?

Thanks.

2
  • Try making the GUI write your .java files according to what the user inputs, though I don't know if that's exactly what you want.... Commented Sep 9, 2015 at 14:24
  • theres no conventional way to do that, except you can add fields using File IO, but in that case you have to compile the Class file again in terms you re-use the newly created properties and this wont be a good idea with JAVA Commented Sep 9, 2015 at 14:25

1 Answer 1

1

If the requirement is that a normal user should be able to add additonal fields to existing objects, propably the best way would be to store the information in a map.

So instead of:

public class User {

private String firstname;
private String lastname;
private String email;
private int id;
}

you would have:

public class User {

private int id;

private Map<String,String> properties;

public User(String firstname, String lastname) {
    properties = new HashMap<String,String>();
    properties.put("firstname",firstname);
    properties.put("lastname",lastname);
}

etc.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.