Subject | Generalization / Domain |
---|---|
Author | kogerbnz |
Post date | 2008-02-20T10:19:05Z |
Hello
Let me start by saying that I'm new in the database world. So now that
you know, here is my problem :-)
I have multiple "items" that share several attributes. So being a
OO-programmer, I instantly think of a class hierarchy. Having a
abstract base class with the common attributes, and then multiple
entity classes inheriting from the abstract base class, and adding
their specific attributes.
But how do I implement such a relationship in Firebird. Here is my idea:
Item table:
ID (PK) (auto incremented)
ItemType (FK or domain, more on that later)
The common attributes
Book table:
ID (PK) (same ID as in item table, so not auto incremented)
The book specific attributes
CD table:
ID (PK) (same ID as in item table, so not auto incremented)
The cd specific attributes
Is that a good generalization design?
About the ItemType column. I see two ways to implement this
1)
Use a ItemType table:
ID int (ID, is going to be foreign key in Item table)
Type string (would be "book" or "cd")
2)
Another way would be using a Domain, it seems easier.
But is domain good practice?
If I in the future would move to another database, would using domain
give me trouble?
Thanks a lot
Let me start by saying that I'm new in the database world. So now that
you know, here is my problem :-)
I have multiple "items" that share several attributes. So being a
OO-programmer, I instantly think of a class hierarchy. Having a
abstract base class with the common attributes, and then multiple
entity classes inheriting from the abstract base class, and adding
their specific attributes.
But how do I implement such a relationship in Firebird. Here is my idea:
Item table:
ID (PK) (auto incremented)
ItemType (FK or domain, more on that later)
The common attributes
Book table:
ID (PK) (same ID as in item table, so not auto incremented)
The book specific attributes
CD table:
ID (PK) (same ID as in item table, so not auto incremented)
The cd specific attributes
Is that a good generalization design?
About the ItemType column. I see two ways to implement this
1)
Use a ItemType table:
ID int (ID, is going to be foreign key in Item table)
Type string (would be "book" or "cd")
2)
Another way would be using a Domain, it seems easier.
But is domain good practice?
If I in the future would move to another database, would using domain
give me trouble?
Thanks a lot