Could someone explain me the object model in Database ? For eg in case of the forums how would my objec开发者_Python百科t model look like for the below tables for designing Internet forums (Not the complete implementation). I want the basic idea regarding object model and how is it different from ER diagram which is based on relational model.
users Table
user_id
forums Table
forum_id forum_name
topics Table
topic_id forum_id user_id topic_name
I understand your question like this: What is the difference between objects and tables? Now, there is no object model in databases (in relational databases, there are also object oriented databases). As you have said yourself there is a relational model.
A table consists of rows and columns (or in old language records and fields). An object consists of data and methods. A table often has primary key as one of its columns (or several columns). A table often has foreign keys used to reference to other rows in other tables or the same table.
In objects you may reference to other objects of the same class or of other classes but this is not the same.
So if you have the above 3 tables and then you write classes representing the content of one row of each table and the classes know how to become persistent by writing into the database table and how to create a object of a class by getting the content from a database table then you are in a chapter where the space of the answer box is not enough.
This is the topic of how to make objects persistent. How to convert object model to relational database model etc. The web is full of discussions about it and there are lots of frameworks, depending on what language you are working in and there is support from databases to this and there is support from languages to this etc.
Also maybe somebody designs the above tables differently in classes and says I want each table be one class and each row be another class ... why not. Probably a good idea. There are many techniques to create data access objects.
精彩评论