I'm trying to figure out how to map my data requirements to objects. I have a typical parent/child database where (eg) a Site object would be the parent to all the User and Notice (family announcement) objects in that website:
Root: - Site : domain.com - User : joe@bloggs.com - User : jane@bloggs.com - Notice : 123 - Notice : 124 etc
But now, I want to add Charities, classified by Category. So I have a Charity::Category object, which can be parent to other Charity::Category objects. But the charities themselves can appear in more than one category, so I have written a Set class, which sub-classes DBObject, to provide set membership.
Root: - Site : domain.com - Charity : Amnesty International - Category : International charities (members : Amnesty Intern +ational) - Category : Children's charities - Category : International (members : Amnesty International +) etc
All well and good. I can ask for Charity::Category->members and get all the Charities in that category
So now I'm thinking... Notices can have Images, Comments, Editors, and Charities. What is the best way to implement this? I see two options:
Notice: 123 - CharityList : 124 (members: Charity1, Charity2) - ImageList : 125 (members: Image1, Image2) etc
so I could say :
@charities = $notice->charity_list->members
Disadvantage : I have to create a number of different classes, and I think it would be more DB intensive
Notice: 123 (members: Charity1, Charity2, Image1, Image2) etc
and I can say:
@charities = $notice->members({type => 'charity'})
Disadvantage : Sets cache their membership lists, and so I would need to cache different types of lists (eg {type => 'Charity'}, {type => 'Charity', status => 'active'}), etc, which would make it trickier.,
Which is the cleaner, more OO solution? (Have I explained my question sufficiently?)
thanksClint
In reply to How to implement set-style membership lists in my obejcts by clinton
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |