• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

inheritance and polymorphism

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ;)
 
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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,

 
reply
    Bookmark Topic Watch Topic
  • New Topic