File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSF and the fly likes inheritance and polymorphism Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "inheritance and polymorphism" Watch "inheritance and polymorphism" New topic
Author

inheritance and polymorphism

David Douillard
Greenhorn

Joined: Nov 23, 2007
Posts: 1
Hi,

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?


Thanks and sorry for my poor English ;)
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
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,

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: inheritance and polymorphism