
June 4th, 2012, 09:28 PM
|
 |
Contributing User
|
|
Join Date: Aug 2002
Location: Queensland, Australia
|
|
|
Table structure for extended objects
I'm curious if there is a pattern for storing programming objects in a database where one class may extend another.
So, for example, you might have an abstract class for a media that has nothing more than an ID property. Two other classes extend to for Flash media and Text media. These each have different properties, but they still have an ID which must be unique regardless of the type.
So when it comes to storing these media in the database, it would be kinda ugly to have one single table that describes all possible media types--especially as more and more types are created. It seems better to have a media table that stores an ID and a `type` and then have a separate table for each type.
But having a separate table for each type won't prevent a Flash media rowing being created with the same ID as a Text media.
So is there a better DB design that compliments this? Or is what i've described as good as it gets and then code must be used to ensure the same ID is not reused for different media.
I know I could also add a `type` column to each of the media type tables which can only contain one value, then make that a foreign key... but having a column that can only contain one value seems redundant.
__________________
Ooh, they have the Internet on computers now!
|