0

Which approach is more best practice? I have a database with Products table and Categories table. Product always has its category. Now I am implementing the Product entity class and I do not know if it is better to have an int property "category_id" or object property with Category class. So if the contructor should be:

    public Product(int id, int category_id)

or

    public Product(int id, Category category)

Which of these is better? Or should I use both properties?

thanks for reply

4

1 回答 1

0

第二个。它更简洁,您可以随时更改类别标识符。

此外,它的类型更安全,因为您无法将一些任意的“int”值传递给第二个参数。您无需考虑哪个“int”负责“id”,哪个负责“category_id”(如果缺少文档)。

于 2013-05-03T21:26:33.780 回答