0

if you have 2 entities (teacher) and (student) both of them has a common attribute so I don't want to repeat the attributes on each table eg (name, age, address, mobile etc..)

so can I make supper class called human with two subclasses one for teacher and second for the student ?

if that valid -> how to connect the two subclasses with the super class? should I use flag of foreign key?

and for retrievingdata, how to do so as per half of the data on subclass and another have is on the supper class ?

thank you

Alex P
  • 11
  • in SQL think about tables and not classes. DB usually not have concept of derriving in OOP sense (sometimes: postgresql has). Use relation to table address – Jacek Cz Dec 14 '17 at 15:46
  • 2
    Please read https://stackoverflow.com/questions/1567935/how-to-do-inheritance-modeling-in-relational-databases – reto Dec 14 '17 at 15:47
  • Will you ever want to select all persons named Smith or persons older than 17, no matter whether teacher or student? For such queries a common person table might be helpful. But I think I would just have the columns in both tables and not worry. You could still run above queries, but mainly you will either query students or teachers, not "persons", so that both are persons is nothing your database has to be aware of. – Thorsten Kettner Dec 14 '17 at 16:19
  • Are you asking question about database or classes??? – Eric Dec 14 '17 at 17:43

0 Answers0