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

Make the Hospital class more generic

Jacky Luk
Ranch Hand

Joined: Aug 02, 2012
Posts: 580


You see there will be a problem here. When I add a new hosptial to the mess, I have to add a new class to retrieve a specific hosptial patient info, how do I make the Hospital class more generic?
So that no matter how many hospital I add to the database, I don't have to add a new class to the application?
Thanks




Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Kind of hard to answer since we don't know what makes one hospital different from the others.

Just the id?
Pass the id as a param to the method, change your SQL to "... where h.Hospital_ID = ?", and use PreparedStatement's setInt() (or setXxx for whatever type is appropriate) method.

Different table structure but same patient data being returned?
Make the Hospital class abstract, and declare a protected abstract method that fetches the data and puts it into the patient data structure. The public, concrete method calls that abstract method.

Totally different patient data?
Have the patient data classes implement an interface that exposes the common business view of that data. Implementations transform from hospital-specific patient data to your common form as appropriate. Hospital classes are declared to return the patient interface type, and return the implementation appropriate for that hospital.

Those are rough ideas based on guesses about some of the kinds of issues you might be facing. You really haven't made your problem clear (you didn't TellTheDetails(←click), so it's hard to give any concrete advice.
Jacky Luk
Ranch Hand

Joined: Aug 02, 2012
Posts: 580
Jeff Verdegan wrote:Kind of hard to answer since we don't know what makes one hospital different from the others.

Just the id?
Pass the id as a param to the method, change your SQL to "... where h.Hospital_ID = ?", and use PreparedStatement's setInt() (or setXxx for whatever type is appropriate) method.

Different table structure but same patient data being returned?
Make the Hospital class abstract, and declare a protected abstract method that fetches the data and puts it into the patient data structure. The public, concrete method calls that abstract method.

Totally different patient data?
Have the patient data classes implement an interface that exposes the common business view of that data. Implementations transform from hospital-specific patient data to your common form as appropriate. Hospital classes are declared to return the patient interface type, and return the implementation appropriate for that hospital.

Those are rough ideas based on guesses about some of the kinds of issues you might be facing. You really haven't made your problem clear (you didn't TellTheDetails(←click), so it's hard to give any concrete advice.


Thanks Jeff, since the model is fairly simple at this stage, I think what you suggest is sufficient for the first iteration of developement. I will add things later on.
But Could you please provide a code snippet? I don't know how to approach this
Jack
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Jack Luk wrote:
But Could you please provide a code snippet?


No, because A) This site is NotACodeMill(←click), and B) I still have no idea what you're trying to do or what problem you're having.

I provided 3 hypothetical potential scenarios to give you an idea of what you need to explain if you want help and what kinds of general approaches you might take. I don't know which of those 3 suggestions your'e saying is sufficient. I also don't know what you mean by "different hospitals."
Jacky Luk
Ranch Hand

Joined: Aug 02, 2012
Posts: 580
Jeff Verdegan wrote:
Jack Luk wrote:
But Could you please provide a code snippet?


No, because A) This site is NotACodeMill(←click), and B) I still have no idea what you're trying to do or what problem you're having.

I provided 3 hypothetical potential scenarios to give you an idea of what you need to explain if you want help and what kinds of general approaches you might take. I don't know which of those 3 suggestions your'e saying is sufficient. I also don't know what you mean by "different hospitals."


Let's say I have a Hosptial Table
ID Hosptial Name
1 Queen Mary Hospital
2 Eastern Hospital

In my case, I use 2 different methods to retrieve their data, if I add one more hospital, then it is another labor
When I say Different Hospital, they are not very different at all. They all contain the same data.
The only concern is I want to make an abstract class so that when I read a specific hospital data and the patients inside it, I can just use its id to differentiate it and don't have to re-create every time a new class to handle a new hospital record.

My question basically is,
Do I make concrete classes for every hospital? because I can't instantiate a AllPatient<PatientRec> data = new AllPatient<PatientRec>();
Here AllPatient is abstract?



Thanks
Jack
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Jack Luk wrote:
Let's say I have a Hosptial Table
ID Hosptial Name
1 Queen Mary Hospital
2 Eastern Hospital

In my case, I use 2 different methods to retrieve their data, if I add one more hospital, then it is another labor
When I say Different Hospital, they are not very different at all. They all contain the same data.


So the only difference is sometimes you retrieve the data for the Hospital with ID 1 and sometimes the Hospital with ID 2? Then no, of course you don't need a different class for each Hospital. You just pass the Hospital ID to your method instead of hardcoding 1, 2, etc. If it's not immediately obvious what that means or how to do it, then you're trying to run before you can walk, and you need to go back and learn the fundamentals of Java before messing around with more advanced stuff like JDBC.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Make the Hospital class more generic
 
Similar Threads
type of argument lost?
Array and mapping
Returning a 0 value error
How do I bind a ResultSet to a multiple columns TableModel?
Spring security: initializing bean after succesful authentication?