Using a TravelAgency and a Flight class to implement business logic
Anonymous
Ranch Hand
Joined: Nov 22, 2008
Posts: 18944
posted
0
Hello list, My approach to the Flight By Night Services was the following: I created a TravelAgency class that worked on top of the "Database" class/interface in order to retrieve flights and book seats (effectively providing a Travel Agency Service). A possible interface for this class might be: public interface TravelAgencyInterface extends Remote { public Flight[] searchFlights( String originAirport, String destinationAirport ) throws RemoteException, DatabaseException; public Flight bookSeats( Flight aFlight, int numberOfSeats ) throws RemoteException, DatabaseException, IOException; public String[] getAllOriginAirports() throws RemoteException; public String[] getAllDestinationAirports() throws RemoteException; public String[] getFlightAttributes() throws RemoteException; } Those methods can surely throw other exceptions (e.g. BookingException) but that is not what I wanted to emphasize here. I also used another "wrapper" class which is Flight, and wraps a "database record" class/interface into a flight object. A possible interface might be: public interface Flight { public String[] getFieldNames(); public boolean equals( Object anObject ); public String[] getFieldValues(); public String getFlightNumber(); public String getOriginAirport(); public String getDestinationAirport(); public String getCarrier(); public double getPrice(); public String getDay(); public String getTime(); public String getDuration(); public int getAvailableSeats(); } I'd like to hear some opinions on my approach... Is it my own thought or does the assignment requires us to "expose" the Data class public interface through a network connection (in my case RMI)??? Is it wrong if I offer a remote TravelAgency instead of a remote Data??? Has anybody who completed the certification followed my approach??? How do you feel about this??? If somebody didn't follow my approach, how do you access the information in a flight record??? Do you use the name of the database field for accessing flight properties in your GUI code (use something like data.getValues()[3] instead of something like flight.getAvailableSeats() )??? I hope I receive some comments... Thanks, Benjam�n....
Cleland Early
Ranch Hand
Joined: Apr 16, 2001
Posts: 38
posted
0
I'm finishing up my assignment, and I didn't take your approach, which strikes me as more complicated than it needs to be. I subclassed AbstractTableModel and used my subclass both to map database records to table rows and columns and as a wrapper for the database calls. Most of the fields in the assignment's database records are irrelevant, except that you want to display them in a table in a window, and you don't need a Flght object to do that.
Rich Wardwell
Ranch Hand
Joined: Jan 20, 2000
Posts: 33
posted
0
Wow... I went exactly the same route - almost to the T. Started with Flight objects and a very similar interface to the one you had to provide access to them, then when I started to think about the added complexities, threw it out and switched over to just holding the data and accessing through the AbstractTableModel interface. I'm still torn whether not providing accessors that return Flight objects isn't more appropriate, but it certainly muddies things. Simple or flexible / complex. Also, creating a ton of flight objects seems somewhat ineffecient, although that wasn't a motivating factor in me switching.
<B>Rich Wardwell</B><BR> <A HREF="mailto:rcw3@levelpath.com" rel="nofollow">rcw3@levelpath.com</A> <BR>Sun Certified Programmer for the Java 2 Platform
subject: Using a TravelAgency and a Flight class to implement business logic