The Design of Software (CLOSED)

A public forum for discussing the design of software, from the user interface to the code architecture. Now closed.

The "Design of Software" discussion group has been merged with the main Joel on Software discussion group.

The archives will remain online indefinitely.

ORM

Hello, I'm working on a personal ORM.

Take for example,
Person Rents Car
Many-Many Association

Person: ID, Name, Address
Car,: ID, Comments, Purchase Date
Rent PersonID, CardID, RentDate, RentEndDate

Then I create Person, Car and Rent Objects. Then there is a method that allows

getCarsRentedByPerson ( P )

This returns a list of all Car objects rented by that Person. It doesn't return a list of "Rent" objects.

So I was thinking that maybe it would be better to take the attributes from the association table (RentDate and RentEndDate) and place them on the Car objects *when* they are retrieved by that method.

CarRent extends Car
  private Date RentDate
  private Date RentEndDate

So the getCarsRentedByPerson would return CarRent objects instead of Car objects.

What I would like to achieve is that the user doesnt actually need to know about those mapping Rent objects.

Comments on this approach?

Thanks.
BladeFan0
Friday, September 28, 2007
 
 
For your example, this doesn't sound like something you'd want to do. Rental cars are going to have a long history of rentals and so if I called your method and I had rented the same car multiple times (I travel a lot for work and have gotten the same car more than once before) would I get back three different RentCar objects all with their own start/end dates but with the same VIN #, etc?

Seems better to attach a RentalHistory object or something to every car.

Friday, September 28, 2007
 
 
I agree with the previous poster's sentiment.

Personally, I'm confused as to why you'd want to have all that data (i.e. all the past cars and rental dates). What scenario are you trying to support. It doesn't seem like very useful information.

I can understand wanting to know what cars (or types of cars) someone has rented because you can figure out their preferences, perhaps. I think you should come up with the most demanding scenario that you want to support *right now* and then support that. What's right in the code depends on the context in which you are writing it.
Captain Confused
Friday, September 28, 2007
 
 
Given the name of your method (getCarsRentedByPerson) it would be unexpected for the method to return anything OTHER than a collection of cars (with each car appearing exactly once in the collection). If you change the name of the method (getCarRentalsByPerson) then, of course, it would make sense to return the kind of data you are talking (a car along with the period during which it was rented by the person, where the car may appear multiple times with different rental periods).
Jeffrey Dutky Send private email
Friday, September 28, 2007
 
 
<quote>
What scenario are you trying to support. It doesn't seem like very useful information.
</quote>

Well I'm working on a ORM to adapt to several situations. Thats a typical Many to Many... the coder may need the other info, or he may not. Thanks.
BladeFan0
Saturday, September 29, 2007
 
 
The approach is retarded. Sorry.
Don't inherit two important entities together, they're separate for a reason.
Inhertiance is a useful tool until you mis-use it like this, then it becomes crap and counter-productive.

Just return the Rental objects as they reference the Vehicle anyway. Then display them to the user and show the Vehicle property to the UI.
Jax
Monday, October 01, 2007
 
 
Hmmm I guess I didn't understand the question first time round. Sorry! :).
Let me rephrase:

If your just looking to provide a many-to-many just use a set (no duplicates) collection.
It's really not worth polluting the ORM or the inheritance model to be clever like this. What you're essentially doing is stating that the rental and the vehicle objects are the same thing. This is not so, they have a many-to-one relation (many rentals to one vehicle).

If the consumers of the ORM want to show the information about past rentals they'll just traverse the Person->Rental-> Vehicle path to get those details.
The code will get the rental objects out of datastore, then display the vehicle (via the Rental->Vehicle association) and the rental dates beside it.

Then if the user of the ORM wants to show just the cars the Person has hired in the past use the many-to-many traversal and they won't get duplicates.
Jax
Monday, October 01, 2007
 
 

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics
 
Powered by FogBugz