I am a Computer Science student and one of my first class was Object Oriented Design (Java). Unfortunately, we never interacted with a database during that class. I am currently working on a CRUD app as a side-project and I am confused about the relationship between Objects and DB Tables.
Let’s say I am making a persistent browser war game in Python (such as Travian), where each user has 1 or more
village has different buildings and troops.
Using MySQL, I could represent a
village like this:
CREATE TABLE `village` ( `village_id` int NOT NULL AUTO_INCREMENT, `user_id` int NOT NULL, `city_name` varchar(100) NOT NULL, `location-x` int(3), `location-y` int(3), `population` int(5), KEY `user_id` (`user_id`), CONSTRAINT `user_id` FOREIGN KEY (`user_id`) REFERENCES `user` (`user_id`), PRIMARY KEY (`village_id`) )
I could also make a class to represent a village using Python. But if my Class components are the same as my Table columns, isn’t a waste of resources? Like rather than updating the object, why not directly interact with the database table and directly
read, write, update values directly on the table rather than the object?