In my Java code I have these three classes. Basically I have a User class, and also a GUI class that holds TextView
s and other things (GUI related) for the properties that show on the screen.
The SearchUser
is just a object that has the GUI properties. One of these per user object.
I noticed that both the user class and the SearchUser
class share the same properties, so I took them out and made a BaseUser
class, and then extended it to have that.
I don't think the way I structured this is good for Java programming practices. I think some sort of encapsulation or something will be better but I'm not sure what I can do here.
I need the user object and GUI object to also be separate for modularity purposes.
Does anyone see a better way of writing the below code?
BaseUser.java
package sord.object;
public class BaseUser {
int userid;
String firstname;
String lastname;
String emailaddress;
int roleId;
Boolean active;
String picURL;
}
User.java
package sord.object;
import java.util.Date;
import android.content.Context;
import sord.common.DateTimeFunctions;
public class User extends BaseUser {
private String password;
private String phoneNumber;
private String websiteLink;
private String statusText;
private String bioText;
private Date dateJoined;
private Date dateLastActive;
public User(int userid, String firstName, String lastName,
String password, String emailAddress, String phoneNumber,
String websiteLink, String statusText, String bioText, int roleId,
String dateJoined, String dateLastActive, int active,
String picURL, Context context) {
this.userid = userid;
this.firstname = firstName;
this.lastname = lastName;
this.password = password;
this.emailaddress = emailAddress;
this.phoneNumber = phoneNumber;
this.websiteLink = websiteLink;
this.statusText = statusText;
this.bioText = bioText;
this.roleId = roleId;
this.dateJoined = DateTimeFunctions.ConvertStringToDate(context, dateJoined, false);
this.dateLastActive = DateTimeFunctions.ConvertStringToDate(context, dateLastActive, true);
this.active = active == 1;
this.picURL = picURL;
}
public int getUserId() {
return userid;
}
public String getFirstName() {
return firstname;
}
public String getLastName() {
return lastname;
}
public String getPassword() {
return password;
}
public String getEmailAddress() {
return emailaddress;
}
public String getPhoneNumber() {
return phoneNumber;
}
public String getWebsiteLink() {
return websiteLink;
}
public String getStatusText() {
return statusText;
}
public String getBioText() {
return bioText;
}
public int getRoleId() {
return roleId;
}
public Date getDateJoined() {
return dateJoined;
}
public Date getDateLastActive() {
return dateLastActive;
}
public Boolean getActive() {
return active;
}
public String getPicURL() {
return picURL;
}
}
SearchUser.java
package sord.object;
import java.util.ArrayList;
import android.widget.LinearLayout;
import android.widget.TextView;
public class SearchUser extends BaseUser {
public Boolean origActive;
public Boolean selected = false;
public Boolean deleted = false;
public Boolean edited = false;
public TextView nameView;
public LinearLayout userLayout;
private ArrayList<PlacementGUI> placementList = new ArrayList<PlacementGUI>();
public SearchUser(int userid, String firstname, String lastname,
String emailaddress, int roleId, int active, String picURL) {
this.userid = userid;
this.firstname = firstname;
this.lastname = lastname;
this.emailaddress = emailaddress;
this.roleId = roleId;
this.active = active == 1;
this.picURL = picURL;
this.origActive = active == 1;
}
public void AddPlacement(PlacementGUI placement) {
placementList.add(placement);
}
}