In my application, I have an abstract base class, and 2 derived classes. The number of derived classed will probably not increase. If it does, it won't be more than a few.
The class structure looks like this:
abstract class Base
{
int FirstParameter
int SecondParameter
abstract void DoSomeWork();
}
class Foo : Base
{
int FoosParameter
override void DoSomeWork(){...}
}
class Bar : Base
{
override void DomeWork(){...}
}
Essentially, Bar
only needs the data provided by Base
, but does its own work on the data. From a data standpoint, Bar
and Base
are the same. Foo
, on the other hand, has some extra data tacked on to it.
The database has 3 tables, one for Base
, one for Foo
, and for Bar
. Since the number of subclasses is not going to grow significantly, it makes more sense to give each class its own table.
tblBase:
base_id PK,
first_parameter int not null,
second_parameter int not null,
foo_id int,
bar_id int
tblFoo:
foo_id PK,
foos_parameter int not null,
tblBar:
bar_id PK
tblBar
consists of 1 column, which is the auto incrementing primary key. The primary key is stored in tblBase
in column bar_id
, which will identify any Base
as being a Bar
.
Now, for the real kicker: How does one insert a new record into tblBar
, when the only column is the auto incrementing primary key? I suppose I could do
insert into tblBar(bar_id)
select max(bar_id) + 1
from tblBar
but that seems a bit....clunky.