Hi,
I have this Product class which is related to several other classes, e.g. Category, Designer, etc. In database, I have column CategoryID, DesignerID. When defining a Product class, shall I have Integer property for CategoryID, DesignerID? Or, shall Ihave String property for CategoryName, and DesignerName?
Solution 1: Integer Property
When I display a product, I'll initialize a Product class, get the CategoryID and DesignerID, and then initialize Category class and Designer class, to get the Category name and Designer name to display. That means I will access database 3 times.
Solution 2: String Property
When I display a product , I'll initialize a Product class, use a JOIN SQL statement, and set Category name and Designer name directly.
So, which is the proper solution? I think Solution 1 is the correct one. But what can I do to eliminate 3-time database accessing?
Thanks,
Nicole
I have this Product class which is related to several other classes, e.g. Category, Designer, etc. In database, I have column CategoryID, DesignerID. When defining a Product class, shall I have Integer property for CategoryID, DesignerID? Or, shall Ihave String property for CategoryName, and DesignerName?
Solution 1: Integer Property
When I display a product, I'll initialize a Product class, get the CategoryID and DesignerID, and then initialize Category class and Designer class, to get the Category name and Designer name to display. That means I will access database 3 times.
Solution 2: String Property
When I display a product , I'll initialize a Product class, use a JOIN SQL statement, and set Category name and Designer name directly.
So, which is the proper solution? I think Solution 1 is the correct one. But what can I do to eliminate 3-time database accessing?
Thanks,
Nicole