I have this class:
public class Book extends SugarRecord {
private Long id;
private String mBookName;
private String mAuthorName;
private List<Page> mPageList;
public Book() {
}
public Book(String bookname, String authorName) {
mBookName = bookname;
mAuthorName = authorName;
mPageList = new ArrayList<>();
}
public Book(String bookname, String authorName, List<Page> pageList) {
mBookName = bookname;
mAuthorName = authorName;
mPageList = pageList;
}
@Override
public Long getId() {
return id;
}
@Override
public void setId(Long id) {
this.id = id;
}
public String getAuthorName() {
return mAuthorName;
}
public void setAuthorName(String authorName) {
mAuthorName = authorName;
}
public String getBookName() {
return mBookName;
}
public void setBookName(String bookName) {
mBookName = bookName;
}
}
The Page class isn't much but just in case:
public class Page {
private Long id;
private String mText;
public Page() {
}
public Page(String text) {
mText = text;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getText() {
return mText;
}
public void setText(String text) {
mText = text;
}
}
Right now I figure it makes sense to have two constructors, one for if you have pages already and one if you don't, but is this the right way to go about it? Or do I need to copy the ArrayList that comes into the constructor as opposed to merely referencing it?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…