Sorry, when writing "at least it always does for me", I had overlooked that SubCategory is a subclass of category.
The reason I overlooked it is that all my superclasses are abstract. I would set up my class hierarchy as something like
Code:
abstract class Category{
id
name
set subCategory
}
class MainCategory extends Category{
}
class SubCategory extends Category{
Category parent
set object of other type
}
At first glance, this looks like two additional lines to write without any payback. But I bet quite soon you'll want to reference those category trees from somewhere in your application. Then it does make a difference whether you can only write
Code:
...
Category c // can point both to categories or subcategories
...
or
Code:
...
MainCategory c // here you can be sure it points to the root of the tree
...