You are viewing [info]tithonium's journal

 
 
04 April 2011 @ 08:09 pm
Names are hard  
You have Object A and Object B. You need to call a method on A, passing B as a param, to return the relationship of B to A. You'll get back answers like :owner (if A==B, or A.creator == B, or A.owner == B, or something like that), :friend (if A considers B a friend, or A is a group and B is a member, etc), or :other (if neither of the others).

If we were calling the method on B and passing A, I'd say B.relationship_to(A). But what do I call it in the other direction? A.xxx(B)? I don't like .relationship_from, 'cause that sounds kinda stupid. I'm looking for better ideas.

edit:

May as well be more concrete.

The logged in user, the person doing the browsing, is represented by 'current_profile'.
Now, if you're looking at someone else's profile, they'll be @profile. Or if you're looking at a group, it's @group. Or an event, it'll be @calendarItem (Event was taken). I'm defining an API that all three of these things share, and want to be able to say things like @profile.xxx(current_profile), instead of current_profile.relationship_to(@profile). It's entirely an aesthetic thing, there's no strong reason for wanting it this way.

editedit:

Well, ok, that's not /strictly/ true. It's /mostly/ aesthetic. But there's also the question of the 'friend' state, which will be based on relationship objects from A, not from B. so, if I'm calling B.relationship_to(A), the function on B will end up searching thru A.friends for itself, which just Feels Weird. If the actual implementation of this function was going to be different for each of the classes, then it would /have/ to be this way, since we don't want a Profile to need to know how to find the 'friends' of an Event. But since I'm planning to implement it once, in a module they'll all include, that's not an issue.
 
 
( 9 commentations — Encommentate )
Stax[info]staxxy on April 5th, 2011 03:13 am (UTC)
call it George
[info]eub on April 5th, 2011 04:53 am (UTC)
Presuming that the set of relations is closed under symmetry, you could call relationship_to() and then ask the result to flip itself around.
Laurentina's skeleton[info]stolen_tea on April 5th, 2011 05:14 am (UTC)
So, if I get the question right, if B owns A, then you could call B.relationship_to(A) and get "owner", and A.relationship_to(B) and get "owned_by". But you're looking for a method name for calling A.xxx(B) and getting "owner". Right?

Ooof. No good ideas right now...
Darkmane[info]darkmane on April 5th, 2011 07:24 am (UTC)
determineRelationship
Obj A = new Obj()
Obj B = new Obj()
print A.determineRelationship(B)

or maybe getRelationship.
Jedi Freeman[info]jedifreeman on April 5th, 2011 01:25 pm (UTC)
relationship_with would be a good neutral name for this method as well.
Apophenia[info]jodawi on April 7th, 2011 06:46 pm (UTC)
A.thereThereJustLieBackOnTheCouch();
A.letsTalkAboutYourFeelingsRegarding(B);

for improved answers, might need more context. feels a little like the relationship is a bundle of concepts that might be more cleanly dealt with in a less bundled way.

Martin Tithonium[info]tithonium on April 7th, 2011 07:48 pm (UTC)
This is the project where I'm mixing polymorphic associations and single-table inheritance Because I Can.

So, you have Profiles, Groups, and Calendar Items.
And then you have Connections

A connection can connect any of the first three items to any of the others.
In practice, it always has a profile on at least one side.
CalendarItem->Profile = invitation to event
Profile->Profile = friend
Group->Profile = member of group

The person viewing a given page, which might be for a profile, a group, or a calendaritem, OR a list of the same, will always be represented by a Profile.

The relationship between the item being viewed and the person doing the viewing is what determines what we show to the viewer.

So, I want to be able to call [thing].[verb]([viewer])
The result will be a symbol, something from the set [:owner, :friend, :guest]. I might add more later, if I need to get more granular, but not right now.

However, the phrasing of those returns implies the direction of the relationship. If I, the viewer, created the Group that I am looking at, then I am its :owner. It is not my :owner. But I want the method to return :owner in this case. So, I need a verb that implies viewer's relationship TO thing, but which is grammatically sensible to be called on thing.

Right now I'm using relationship_from, but I don't like it.
Martin Tithonium[info]tithonium on April 7th, 2011 07:51 pm (UTC)
Things are mildly complicated by the fact that I'm not yet decided about reciprocal relationships. I think at least profile-to-profile connections need to be reciprocal. Especially since the 'hidden' field - meaning I don't see them in my wall - is an attribute of the connection.

But do I need to reciprocate calendaritem relationships? or groups? An invitation to join a group that you did not initiate yourself would require approval before it had any effect anyway, and the group wouldn't need to 'hide' you (since your wall posts won't show up on it anyway, unless you post directly to it). Ditto with calendar items.
Apophenia[info]jodawi on April 11th, 2011 02:58 pm (UTC)
This is the project where I'm mixing polymorphic associations and single-table inheritance Because I Can.

"...Tithonium software /
We code what we must, because we can..."


Maybe the relationship needs to be a triple of values, including references to the two participants. The method for all could then be getRelationship, with directionality built in to the relationship object rather than the method name.
( 9 commentations — Encommentate )