Re: many-to-many relationships and object design
Re: many-to-many relationships and object design
- Subject: Re: many-to-many relationships and object design
- From: Tim Hart <email@hidden>
- Date: Fri, 18 Jun 2004 13:11:58 -0500
To touch on a slightly different aspect of this...
Everything everyone else has said is completely valid.
Having done very similar projects in the past, you may want to consider
a single 'higher up' object that knows about all of the actors and
scenes in relationship with each other - possibly a 'Play' object?
In my case, I had a land title which referred to one or more parcels of
land. I also had a parcel of land which was related to one or more
titles.
My life and my code became significantly more simple when I created a
TitleParcelGroup class. A single point to find out about all the titles
and parcels in relation to each other. Note that this object was not
technically required by the client, but finding all the titles and
parcels related to a particular legal action was much simpler this way
than trying to navigate an object graph for a single title or parcel -
and making sure I had the entire collection.
There was an RDBMS table backing up the TitleParcelGroup as well.
Assuming I'm close on assuming that a Play object might work for you -
obviously scenes are only members of a single play, while actors may be
involved in several plays. The analogy still works fairly well.
On Jun 17, 2004, at 8:39 PM, Todd Ransom wrote:
Hello,
I'm new to Cocoa, Objective-C and OOP but I recently started a project
to create an outliner app for writers. I have been struggling with
how to design my model objects.
My current model is simple - I have an NSDocument subclass. This
class has arrays of objects for actors and scenes. This works great
until I want to create a relationship between the two. An actor can
participate in multiple scenes and a scene can contain multiple
actors.
I have considered creating a relationship class that would act as a
table (like a relationship table in a RDBMS) but this seemed like it
would be complicated to implement. I tried storing an array of actors
in each scene object but then I needed a way for the scene to resolve
actor ids to actor objects. Since the actor objects only know about
themselves I put this in the NSDocument subclass. But now I can't
seem to think of a reasonable way for the scene objects to know which
instance of the NSDocument subclass they belong to. I get the feeling
that I am trying to work my way through a problem that has a fairly
simple solution if only I had more experience with OO design.
Any pointers to info, suggested solutions, or links to source on this
would be greatly appreciated. I looked at Apple's docs on "object
modeling" but I couldn't turn the abstract information there into any
real ideas on how to implement this.
thanks,
TR
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.