HAS-A vs ORGANIZES-A
Does a blog have posts?
It’s not a stupid question. The answer may seem obvious but when modelling object-oriented systems even seemingly obvious questions may require closer examination.
In this case, for example, I’d suggest that there isn’t a HAS-A relationship between a
Blog and a
Post. Why? Because a Blog is just one possible way, out of many, that a person might use to get their hands on Posts. You might also use an
Tag or even a plain old
Date object to get Post objects.
Sure, some of these relationships aren’t as central as the others. But is the relationship between Blog and Posts really any more “primary” than the relationship between Author and Posts? I’d suggest not. And since the HAS-A relationship should be unique — Blogs and Authors can’t both HAS-A Post objects — I’d propose neither does.
The fact that there are so many different ways to get to Post objects suggests that the concept of a Post is in fact more important than any of the other concepts — like Blog, Author, Category, Tag and Date — that can be used to group a collection of Posts. That is these other concepts are secondary to Post precisely because they’re all just different ways of organizing the universe of Post objects. The relationship between Blog and Posts might then best be understood as an ORGANIZES-A relationship than a HAS-A relationship.