samedi 25 juin 2016

How do I integrate inheritance technique when writting the database

I am trying to use inheritance for sake of re-usability and I have a base class named 'Partner' and two sub classes 'Lawyer' and 'Accountant' as below:

abstract class Partner{

}

class Lawyer extends Partner{

}

class Accountant extends Partner{

}

It's all good with the code, but I was wondering more when it comes to database, how do I store these information in db, should I have one table partners for both entities, or I should have separate tables for each entity, based on fact that these two differs from each other based on their attributes. If I keep it in separated tables, and I have another table 'cases' which is related to partner: cases: case_id, subject, description,partner_id.... My question is, how do I inner join entities based on user logged in, let say if he is laywer join lawyer table or vice versa, what if I keep adding more entities in future?

How would I do it in such a way that eventhou in future I add more Entities my db queries will not have to be changed again and again.

Aucun commentaire:

Enregistrer un commentaire