concept object model in category asp.net

appears as: n object model, The object model, object model, object model
ASP.NET 4.0 in Practice

This is an excerpt from Manning's book ASP.NET 4.0 in Practice.

At this point, we need to emphasize that you need to use different classes to handle different scenarios, and an object model to contain and present data in your application.

You need to create an internal network of classes (the object model) that holds data that can be filled from a query in the database. These classes also need to handle data that updates the database. The classes are Order, Customer, Order_Detail, and Product. They contain properties that represent data on the database and that are useful for business.

Another difference between the relational and OOP models is in the way they maintain relationships. Think about the order/customer relationship. In a database, you create a CustomerId foreign key column in the Orders table (child table) that points to the CustomerId primary key column of the Customers table (parent table). In the object model, you can reference the customer from the order using a property with the type Customer, so there’s no need for a foreign key property.

In a database the associations are unidirectional from the child table to the parent table. In the object model, associations can be both unidirectional and bidirectional. You can have the Customer property in Order, but you can also have an Orders property in the Customer class. Figure 2.5 shows an example of this design.

Figure 2.5. Orders are related to their customers using a foreign key in the database. The OOP model uses a reference to the object.

In the case of a many-to-many relationship, the differences between a relational database and OOP paradigms grow. Think about the relationship between the Employees and Territories tables in the Northwind database. They’re not related to each other through foreign keys but via a third table: EmployeeTerritories. In the object model, you let the classes refer directly to each other without resorting to a middle class.

2.1.1. What’s an object model?

In many, possibly most, applications, a model can be a simple set of classes that contain data coming from a database and that have only a little behavior. This kind of model is known as an object model. Let’s look at a few of the characteristics of the object model classes.