Forum Moderators: coopster

Message Too Old, No Replies

Object Oriented Design Question

         

keym

7:51 pm on Dec 3, 2006 (gmt 0)

10+ Year Member



When defining object models, what do people feel is a more practical approach: going from the specific to the general, or vice versa?

For example, a reservation system for a tour company takes reservations for hotels, cars, and flights.

A hotel has rooms, and a room has reservations.
A Car Rental company has cars, and a car has reservations.
A Plane has seats, and a seat has reservations.

There are two ways to model this.

1. Create a generic class Reservation, with child classes Hotels, Cars and Planes. To place a reservation the program calls methods of the class Reservations, which invoke methods in Hotels, Cars and Planes.

2. Create three specific classes Hotels, Cars, and Planes. To place a reservation, the program invokes a method in Hotels, Cars or Planes. Each of these invoke a method in the class Reservations.

Which approach do you recommend, and why?

Thanks.

coopster

2:52 pm on Dec 4, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



The deciding factor will likely be that you have methods that can be reused in each of the three. If so, create the reservations class. If you need specifics for each of the three you can extend [php.net] the class.

keym

10:52 am on Dec 5, 2006 (gmt 0)

10+ Year Member



Thanks for the reply.

Do you mean take approach #2?

ie. create classes Hotels, Cars, Planes which extend class Reservations with their specifics. The main program calls methods in classes Hotels,Cars, Planes which invoke methods in class Reservations?

Thanks.

coopster

7:21 pm on Dec 6, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Yes, that would seem most logical to me. The parent class (Reservations) probably does a lot of things exactly the same for any of the other child classes. So you could create the members and methods in your Reservation class and extend that class for any specifics you might need in your child classes.

Stuperfied

12:11 am on Dec 7, 2006 (gmt 0)

10+ Year Member



If I understand you correctly, you could have multiple hotels so you would want the reservations for that hotel, in that particular hotel. Putting the hotel in the reservation, could get a bit confusing and tricky when you try to write a script to do a search on just the hotel reservations and not the airline and car.

eg:
Reservations
Hotel
Reservation
[Room Number]
[Name]
[Check In]
[Check Out]
Rental Company
Reservation
[Name]
[Car Number]
[Pickup Time]
[Drop Off Time]
Airline
Reservation
[Name]
[Destination]
[Departure]
[Arival]
[Gate Number]

To extend the example further.

Records
Quantis
Fieldings
[Reg Fielding]
[France]
[US]
[12/12/06 02:30]
[13/12/06 16:45]
[2]

[edited by: Stuperfied at 12:16 am (utc) on Dec. 7, 2006]