Extending classes in a database

I am working on a php project that is supposed to store information about different buildings and store different types of information depending on the type of building:

Class Building {
    var $location
    var $name
}

The Building class will be extended by classes such as House and Office, so the classes will look like this (just an example)

Class House Extends Building {
    var $numRooms;
    var $numBathrooms;
}

Class Office extends Building {
    var $offices;
    var $sqfoot;
}

The question is how this should be represented in the database (im using MySQL if that matters). Should I use a building table to store the location and name, and then create a table for each of the other classes to store the "advanced" variables? Or am I creating a table for each class? or should the build table have columns for all variables that might be in other classes?

+3
2

Class Inheritance, .

, , , , , . , , , , , , .

, , , Entity-Attribute, . -, , , . , , , , , , .

+2

, , Building, , ( : , , ..), .

, , . , , "" "$ numRooms > 5", ...

+1

Source: https://habr.com/ru/post/1708519/


All Articles