man.get_things() or Thing.get_things_by_man() when Active Records Pattern is used?

There is requirement for a method to get things of a man.  Where to put it?  
man.get_things() or   (static) Thing.get_things_by_man()  ?  
From OO’s perspective, the former sounds more natural.   I was planning to adopt this approach until I found a problem:  it may lead to duplicate db access code because not only men has things.  
Men have things, and animals also have things.  If both have method to get_things(),  duplicate logic is going to happen, unless you extract the common code to a third class, and the two subjects call this common method.    It’s fine, but an overkill in small projects which uses Active Records.  Only small projects use this pattern,  right? 
So I chose the "transcript template" pattern:   Thing.get_things_by_man()  .  The benefits it has include,
1. To avoid the disadvantage man.get_things()  has, explained above
2. To make the position of methods more guessable since it treated everything a "resource", just like how RESTFul urls are expectable.

Leave a Comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.