Jasir
Jasir

Reputation: 697

OOP Associations and database access

My project has a class software and another class OS. A software may support multiple operating systems (My actual problem is much more complex).

I'm not sure how to save it in most effective way in my database. My table structure is as follows:

Table: os

id        name          platform
=================================
winxp     Windows XP    windows
win7      Windows 7     windows
...

Table: softwares

id        name             publisher     os
====================================================
chrome    Google Chrome    google        winxp,win7,...
ccleaner  Ccleaner         piriform      winxp,win7,...
...

Is this the best way? Will this cause any problem when programming with OOP (I use DAO approach) Or should i change it somethig like the following one :

Table: os

id        name          platform
=================================
winxp     Windows XP    windows
win7      Windows 7     windows
...

Table: softwares

id        name             publisher  
=====================================
chrome    Google Chrome    google      
ccleaner  Ccleaner         piriform   
...

Table: os_support

softwareid        os
======================
chrome            winxp
chrome            win7
ccleaner          winxp
ccleaner          win7
ccleaner          win8
...

Upvotes: 0

Views: 41

Answers (1)

user2160375
user2160375

Reputation:

Your current approach is wrong - there would be redundancy in your softwares tables. I'm not sure what you mean by winxp,win7... - storing multiple values in a one cell? It's also wrong way - values should be atomic (1st normal form) - but if you mean duplicating row in software table for each operating system - there will be redundancy - like I said at the beggining.

The second approach looks much better (of course if you get rid of os column in software table).

To be sure that field/tables organization is proper, you should read about normalization. Reffer this. 3rd normal form is that what you need :)

Upvotes: 1

Related Questions