Hi all

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
That's fine, because each User and Notice object is unique in the DB. All objects which live in the database inherit from DBObject, which provides ORM functionality.

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:

  1. Notice is parent to CharityList, ImageList, CommentList, EditorList, and each of these objects inherit from Set, and contain just one class of object (ie just Charities, or just Images):
    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

  2. Notice itself sub-classes Set, and contains any class of object in its membership list:
    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?)

thanks

Clint


In reply to How to implement set-style membership lists in my obejcts by clinton

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.