Design Factors 4: How do you map OOP concepts to relational database design?

Let’s consider a simple sample:

Contact db table: Contact ID (primary key), Contact Name, Contact Address

Employee db table: Employee ID (primary key), Employee Joining Date

Customer db table: Customer ID (primary key), Customer Birth Date

Now to utilize the object oriented inheritance concept in relational database model, we can create a one to one relation with Contact table with Employee and Customer table, where besides primary key, Employee ID and Customer ID will be used as the foreign key of Contact table, regarding the concept that all Employees and Customers are considered as a “Contact” object.

clip_image002

Now if we wish to map this idea to real world OOP code, we will create a business entity named “Contact” which inherited sub classes will be “Employee” and “Customer” business entity. The corresponding BLL and/or DAL (Data Access Layer) class of “Employee” or “Customer” can also be inherited from BLL (Business Logic Layer) and/or DAL class of “Contact” to perform required operations in object oriented manner.

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati
Print | posted on Sunday, April 20, 2008 1:14 PM

Feedback

# re: Design Factors 4: How do you map OOP concepts to relational database design?

left by chirag at 6/30/2008 11:00 PM Gravatar
How do we do this?
Let's say I have these tables.
Product : ProductId(pk), ProductTitle,...
Images : ImgId(pk), ImgName, ImgCategory/type,..,
fkProductId
Files : FileId(pk), FileName,...,fkProductId

How should I create Entity classes for them?

Also let's consider one specific example.
I need to list products.
In the listing I need to show product title, top 2 of the images that are related to this product, and links to to 2 of the files related to this product.

Let's say we are working on a method GetProducts(...) for this purpose.
My question is what kind of Entity Class object this should return.
A Product object with Files Collection and Images Collection as properties?

Let's consider one more scenario.
I need to list all the images for a given product.
I also need to list all the files for a given product.
We work on 2 methods like
GetImagesByProduct(...) and GetFilesByProduct(...)
So what should they return?
An Image class object which has Product object as a property?? Or all/specific product attributes are made properties of the Image class?
Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification: