My application will, upon request, receive information from the database and create an object from this information. I am currently considering two different methods (but I am open to others too!) To accomplish this task:
First method:
class Book { private int id; private String author; private String title; public Book(int id) { ResultSet book = getBookFromDatabaseById(id); this.id = book.id; this.author = book.author;
Method Two:
public class Book { private HashMap<String, Object> propertyContainer; public Book(int id) { this.propertyContainer = getBookFromDatabaseById(id); } public Object getProperty(String propertyKey) { return this.propertyContainer.get(propertyKey); } }
With the first method, I find it easier to control, limit, and possibly access properties, add new properties, however, it becomes smoother using method two.
What is the right way to do this?
source share