• 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

Max. Denny's DVD Project: GUIController class doubt

 
Ranch Hand
Posts: 697
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey all,
While am trying to understand GUIController class in Denny's DVD sample project that is given in Max Habibi's book, I did not understand the following.
/**
* Locates a DVD record by and UPC number.
*
* @param upc A String representing the UPC identifying the DVD record.
* @return A DVDTableModel containing all found DVD records.
* @throws GUIControllerException Indicates a database or
* network level exception.
*/
public DVDTableModel findDVD(String upc) throws GUIControllerException{
DVDTableModel out = new DVDTableModel();
ArrayList dvdArray = new ArrayList();
try{
dvdArray = (ArrayList) this.connection.find(upc);
out.addDVDRecord((DVD) dvdArray.get(0));
}
catch(PatternSyntaxException pse){
log.log(Level.WARNING, pse.getMessage(), pse);
throw new GUIControllerException(pse);
}
catch(Exception e){
log.log(Level.SEVERE, e.getMessage(), e);
throw new GUIControllerException(e);
}
return out;
}
In the above method, I think we are trying to get DVD record that has the given upc number. But inside the method, Max. is calling the find(upc) method instead of the getDVD(upc) method. I don't understand why Max. is using this method and it deviates from the other methods. The other methods are calling their respective methods in the DVDAdapter class or DVDDatabseImpl class.
Can anyone please help me understand the variation in calling this particular method? All inputs are greatly appreciated. Thanks.
 
town drunk
( and author)
Posts: 4118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Satish,
LEt me see if I can help. When you say
The other methods are calling their respective methods in the DVDAdapter class or DVDDatabseImpl class.

what does respective method mean to you?
M
 
Satish Avadhanam
Ranch Hand
Posts: 697
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Max,
First of all, thank you for the reply. I will paste the whole code and will ask my question.
/**
* Locates a DVD record by and UPC number.
*
* @param upc A String representing the UPC identifying the DVD record.
* @return A DVDTableModel containing all found DVD records.
* @throws GUIControllerException Indicates a database or
* network level exception.
*/
public DVDTableModel findDVD(String upc) throws GUIControllerException{
DVDTableModel out = new DVDTableModel();
ArrayList dvdArray = new ArrayList();
try{
dvdArray = (ArrayList) this.connection.find(upc);
out.addDVDRecord((DVD) dvdArray.get(0));
}
catch(PatternSyntaxException pse){
log.log(Level.WARNING, pse.getMessage(), pse);
throw new GUIControllerException(pse);
}
catch(Exception e){
log.log(Level.SEVERE, e.getMessage(), e);
throw new GUIControllerException(e);
}
return out;
}
/**
* Locates a DVD based on a user defined search query.
*
* @param searchString The user defined search String
* @return A DVDTableModel containing all DVD records that met the search
* criteria.
* @throws GUIControllerException Indicates a database or network
* level exception.
*/
public DVDTableModel find(String searchString) throws
GUIControllerException{
DVDTableModel out = new DVDTableModel();
ArrayList dvdArray = new ArrayList();
try {
System.out.println(this.connection);
dvdArray = (ArrayList)this.connection.find(searchString);
Iterator it = dvdArray.iterator();
while(it.hasNext()){
out.addDVDRecord((DVD)it.next());
}
}
catch(PatternSyntaxException pse){
log.log(Level.WARNING, pse.getMessage(), pse);
throw new GUIControllerException(pse);
}
catch(Exception e){
log.log(Level.SEVERE, e.getMessage(), e);
throw new GUIControllerException(e);
}
return out;
}
/**
* Retrieves all DVD records from the database.
*
* @return A DVDTableModel containing all DVD Records.
* @throws GUIControllerException Indicates a database or
* network level exception.
*/
public DVDTableModel getDVDs() throws GUIControllerException{
DVDTableModel out = new DVDTableModel();
ArrayList dvdArray = new ArrayList();
try {
System.out.println(this.connection);
dvdArray = (ArrayList)this.connection.getDVDs();
Iterator it = dvdArray.iterator();
while(it.hasNext()){
out.addDVDRecord((DVD)it.next());
}
}
catch(Exception e){
log.log(Level.SEVERE, e.getMessage(), e);
throw new GUIControllerException(e);
}
return out;
}
/**
* Decrements the number of DVD's in stock identified by their UPC number.
*
* @param upc The UPC of the DVD to rent.
* @return A boolean indicating if the rent operation was successful.
* @throws GUIControllerException Indicates a database or
* network level exception.
*/
public boolean rent(String upc) throws GUIControllerException{
boolean retval = false;
try {
retval= this.connection.rent(upc);
}
catch(InterruptedIOException ie){
log.log(Level.SEVERE, ie.getMessage(), ie);
throw new GUIControllerException(ie);
}
catch(Exception e){
log.log(Level.SEVERE, e.getMessage(), e);
throw new GUIControllerException(e);
}
return retval;
}
/**
* Increments the number of DVD's in stock identified by their UPC number.
*
* @param upc The UPC of the DVD to return.
* @return A boolean indicating if the return operation was successful.
* @throws GUIControllerException Indicates a database or
* network level exception.
*/
public boolean returnRental(String upc) throws GUIControllerException{
boolean retval = false;
try {
retval= this.connection.returnRental(upc);
}
catch(Exception e){
log.log(Level.SEVERE, e.getMessage(), e);
throw new GUIControllerException(e);
}
return retval;
}
-------------
In the above code, if we see for example, in the find(String) method, we are calling the this.connection.find(String), in the getDVDs() method, we are calling this.connection.getDVDs(), in the rent(String) mehod we are calling the this.connection.rent(String) respectively and so on...
But for the first findDVD(String upc) method, we are not calling the getDVD(String upc) method. I am not able to understand why we have this exception? Am I missing something here, Max? Please help me.
Thanks.
 
Max Habibi
town drunk
( and author)
Posts: 4118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're assuming that there is some sort of requirement that the method names match one for one, which is not at all the case.
M
 
Satish Avadhanam
Ranch Hand
Posts: 697
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Max, I understand that there is no requirement like that. But my question is if we know the upc number, then it would be direct if we call the getDVD(String upc) method instead of calling find(String query) method in the findDVD(String upc) method.
We can also write the findDVD(String upc) method like this right?
public DVDTableModel findDVD(String upc) throws GUIControllerException{
DVDTableModel out = new DVDTableModel();
//ArrayList dvdArray = new ArrayList();
try{
//dvdArray = (ArrayList) this.connection.find(upc);
DVD dvd_temp = this.connection.getDVD(upc);
//out.addDVDRecord((DVD) dvdArray.get(0));
out.addDVDRecord(dvd_temp);
}
Would it make any difference if the code is like above? I am a bit confused here because the find() method involves more work to retrieve the DVD than the getDVD() method. And moreover if as we are finding the DVD using the upc number, I think we can directly call the getDVD(String upc) method instead of find(String query) method. Please clarify if I'm wrong.
Thanks Max. Appreciate your help and patience.
 
Max Habibi
town drunk
( and author)
Posts: 4118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, there are two views of this.
In one view, you're increasing the number of methods on the object(and hence, complexity) in order to achieve an increase in performance, even though performance is a non-issue in this project .
Alternately, you're adding a specific method, which clarifies and focuses how the methods on the object are used.
Both are defendable. We just went one way: you may choose to go another.
Al best,
M
 
Satish Avadhanam
Ranch Hand
Posts: 697
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Max, I really appreaciate your patience in clarifying.
Thanks alot.
 
All that thinking. Doesn't it hurt? What do you think about this tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic