SXV
SXV

Reputation: 277

Should I create new class or use the existing one

I have the following BO which is already there in the system

public class userBO
{
    private String userId;
    private String password;
    private String firstName;
    private String midName;
    private String lastName;
    private String userType;
    private String userDepartment;
    private String userAuthority;

    //There are some more fields
    //getter and setter

}

Now I want to built a dropdown in which I will display Name (firstName + lastName) and will use userId as value. So for that I will make a list of object.

So my question is should I use the existing userBO class or should I create new class something like below

public class userDropDwonBO
{
    private String userId;
    private String firstName;
    private String lastName;

    //getter and setter

}

I want to know the answer from Good Architect point of view and also performance point of view, Will there be any better performance if I user new userDropDownBO

Upvotes: 1

Views: 145

Answers (2)

Rami
Rami

Reputation: 7300

If you are going to create a new class beside the existing one named UserBO just for the sake of binding it to the JComboBox, that will definitely be a waste of memory and waste of time as well and also you will need to provide an additional logic to map your original object of type UserBO to the the object of type UserDropDownBO. I would say that your approach maybe applicable in case the BO itself is so complex in dealing with, so that you need to create a separate model to be used in the drop down box.

Upvotes: 0

Nishant Lakhara
Nishant Lakhara

Reputation: 2455

userDropDownBO object will definitely use less memory than the above class.

It is because all your members are private intance variable, everytime a constructor is invoked, a set of all private variables will be created on stack and will be initialized to their default values so will consume more memory and initialization time.

But it solely depend on your requirement:

  1. If other fields are required other than these three fields go for the userBO class.
  2. If other fields are unnecessary but no of objects to be created are small in number, go for userBO.
  3. If other fields are unnecessary but no of objects to be created are very large in number, go for userDropDownBO.

Its a personal opinion and rest is your choice.

Upvotes: 2

Related Questions