This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I would like to have your opinion on the best way of managing the inheritance and the polymorphism. I develop with JSF and EJB3. I have an application allowing to manage articles (books or CD). I have a class mother Article and two class girls book and CD. I have a business layer with the method addArticle(Article article). So I can use CD objet or Book objet as argument.
First question : Must i have to create a page to add a book and a page to add a CD ? How can i use a single page ?
I also wish, to have a page allowing to list all the articles, or all the books or every CD.
To list all the articles, no pb, I have a method listArticles (); With the following request: em.createQuery (" SELECT has Article has ") .getResultList ();
Question 2 : To have only books or CD-ROM, Must I have two other methods listCD with em.createQuery (" SELECT d from disk d ") .getResultList (); and listCd() with em.createQuery (" CD-ROM SELECT c from c ") .getResultList ();? Or may I use only my method listerArticles () and then make a filter at the level of my page JSF?
Regarding your first question. I would say its reasonable to have a single page and decide whether to show book specific fields or CD specific using a parameter.
Now for your second question. I would say its not at all a good idea to get the complete list from DB and filter it out using your code. The idea is why select all when you already know that you are going to remove half - or say few - based on a specific filter. The better would be something like this,