<p>What factors determine which approach is more appropriate?</p>

[{'answer_id': 76832, 'author': 'Loren Segal', 'author_id': 6436, 'author_profile': 'https://Stackoverflow.com/users/6436', 'pm_score': 0, 'selected': False, 'text': '<p>Not nearly enough information here. It depends if your language even supports the construct "Thing.something" or equivalent (ie. it\'s an OO language). If so, it\'s far more appropriate because that\'s the OO paradigm (members should be associated with the object they act on). In a procedural style, of course, DoSomethingtoThing() is your only choice... or ThingDoSomething()</p>\n'}, {'answer_id': 76834, 'author': 'benefactual', 'author_id': 6445, 'author_profile': 'https://Stackoverflow.com/users/6445', 'pm_score': 3, 'selected': False, 'text': '<p>To be object-oriented, tell, don\'t ask : <a href="http://www.pragmaticprogrammer.com/articles/tell-dont-ask" rel="nofollow noreferrer">http://www.pragmaticprogrammer.com/articles/tell-dont-ask</a>.</p>\n\n<p>So, Thing.DoSomething() rather than DoSomethingToThing(Thing n).</p>\n'}, {'answer_id': 76835, 'author': 'Bryan Roth', 'author_id': 299, 'author_profile': 'https://Stackoverflow.com/users/299', 'pm_score': 0, 'selected': False, 'text': '<p>DoSomethingToThing(Thing n) would be more of a functional approach whereas Thing.DoSomething() would be more of an object oriented approach.</p>\n'}, {'answer_id': 76836, 'author': 'Guido', 'author_id': 12388, 'author_profile': 'https://Stackoverflow.com/users/12388', 'pm_score': 0, 'selected': False, 'text': '<p>That is the Object Oriented versus Procedural Programming choice :)</p>\n\n<p>I think the well documented OO advantages apply to the Thing.DoSomething()</p>\n'}, {'answer_id': 76869, 'author': 'Aeon', 'author_id': 13289, 'author_profile': 'https://Stackoverflow.com/users/13289', 'pm_score': 2, 'selected': False, 'text': "<p>If you're dealing with internal state of a thing, Thing.DoSomething() makes more sense, because even if you change the internal representation of Thing, or how it works, the code talking to it doesn't have to change. If you're dealing with a collection of Things, or writing some utility methods, procedural-style DoSomethingToThing() might make more sense or be more straight-forward; but still, can usually be represented as a method on the object representing that collection: for instance</p>\n\n<pre><code>GetTotalPriceofThings();\n</code></pre>\n\n<p>vs</p>\n\n<pre><code>Cart.getTotal();\n</code></pre>\n\n<p>It really depends on how object oriented your code is.</p>\n"}, {'answer_id': 76877, 'author': 'UnkwnTech', 'author_id': 115, 'author_profile': 'https://Stackoverflow.com/users/115', 'pm_score': 0, 'selected': False, 'text': '<p>This has been asked <a href="https://stackoverflow.com/questions/68617/design-question-does-the-phone-dial-the-phonenumber-or-does-the-phonenumber-dia">Design question: does the Phone dial the PhoneNumber, or does the PhoneNumber dial itself on the Phone?</a></p>\n'}, {'answer_id': 76904, 'author': 'Chris Comeaux', 'author_id': 2748, 'author_profile': 'https://Stackoverflow.com/users/2748', 'pm_score': 0, 'selected': False, 'text': '<p>Here are a couple of factors to consider:</p>\n\n<ul>\n<li>Can you modify or extend the <code>Thing</code> class. If not, use the former</li>\n<li>Can <code>Thing</code> be instantiated. If not, use the later as a static method</li>\n<li>If <code>Thing</code> actually get modified (i.e. has properties that change), prefer the latter. If <code>Thing</code> is not modified the latter is just as acceptable.</li>\n<li>Otherwise, as objects are meant to map on to real world object, choose the method that seems more grounded in reality.</li>\n</ul>\n'}, {'answer_id': 76907, 'author': 'Ken Ray', 'author_id': 12253, 'author_profile': 'https://Stackoverflow.com/users/12253', 'pm_score': 0, 'selected': False, 'text': '<p>Even if you aren\'t working in an OO language, where you would have Thing.DoSomething(), for the overall readability of your code, having a set of functions like:</p>\n\n<p>ThingDoSomething()\nThingDoAnotherTask()\nThingWeDoSomethingElse()</p>\n\n<p>then</p>\n\n<p>AnotherThingDoSomething()</p>\n\n<p>and so on is far better.</p>\n\n<p>All the code that works on "Thing" is on the one location.  Of course, the "DoSomething" and other tasks should be named consistently - so you have a ThingOneRead(), a ThingTwoRead()... by now you should get point.  When you go back to work on the code in twelve months time, you will appreciate taking the time to make things logical.</p>\n'}, {'answer_id': 76909, 'author': 'killdash10', 'author_id': 7621, 'author_profile': 'https://Stackoverflow.com/users/7621', 'pm_score': 0, 'selected': False, 'text': '<p>In general, if "something" is an action that "thing" naturally knows how to do, then you should use thing.doSomething().  That\'s good OO encapsulation, because otherwise DoSomethingToThing(thing) would have to access potential internal information of "thing".</p>\n\n<p>For example invoice.getTotal()</p>\n\n<p>If "something" is not naturally part of "thing\'s" domain model, then one option is to use a helper method.  </p>\n\n<p>For example: Logger.log(invoice)</p>\n'}, {'answer_id': 76946, 'author': 'digiguru', 'author_id': 5055, 'author_profile': 'https://Stackoverflow.com/users/5055', 'pm_score': 0, 'selected': False, 'text': "<p>If DoingSomething to an object is likely to produce a different result in another scenario, then i'd suggest you oneThing.DoSomethingToThing(anotherThing). </p>\n\n<p>For example you may have two was of saving thing in you program so you might adopt a DatabaseObject.Save(thing) SessionObject.Save(thing) would be more advantageous than thing.Save() or thing.SaveToDatabase or thing.SaveToSession().</p>\n\n<p>I rarely pass no parameters to a class, unless I'm retrieving public properties.</p>\n"}, {'answer_id': 76960, 'author': 'David Arno', 'author_id': 7122, 'author_profile': 'https://Stackoverflow.com/users/7122', 'pm_score': 0, 'selected': False, 'text': "<p>To add to Aeon's answer, it depends on the the thing and what you want to do to it. So if you are writing Thing, and DoSomething alters the internal state of Thing, then the best approach is Thing.DoSomething. However, if the action does more than change the internal state, then DoSomething(Thing) makes more sense. For example:</p>\n\n<pre><code>Collection.Add(Thing)\n</code></pre>\n\n<p>is better than</p>\n\n<pre><code>Thing.AddSelfToCollection(Collection)\n</code></pre>\n\n<p>And if you didn't write Thing, and cannot create a derived class, then you have no chocie but to do DoSomething(Thing)</p>\n"}, {'answer_id': 76977, 'author': 'Orion Edwards', 'author_id': 234, 'author_profile': 'https://Stackoverflow.com/users/234', 'pm_score': 5, 'selected': True, 'text': '<p>I think both have their places.</p>\n\n<p>You shouldn\'t simply use <code>DoSomethingToThing(Thing n)</code> just because you think "Functional programming is good". Likewise you shouldn\'t simply use <code>Thing.DoSomething()</code> because "Object Oriented programming is good".</p>\n\n<p>I think it comes down to what you are trying to convey. Stop thinking about your code as a series of instructions, and start thinking about it like a paragraph or sentence of a story. Think about which parts are the most important from the point of view of the task at hand.</p>\n\n<p>For example, if the part of the \'sentence\' you would like to stress is the object, you should use the OO style.</p>\n\n<p>Example:</p>\n\n<pre><code>fileHandle.close();\n</code></pre>\n\n<p>Most of the time when you\'re passing around file handles, the main thing you are thinking about is keeping track of the file it represents.</p>\n\n<p>CounterExample:</p>\n\n<pre><code>string x = "Hello World";\nsubmitHttpRequest( x );\n</code></pre>\n\n<p>In this case submitting the HTTP request is far more important than the string which is the body, so <code>submitHttpRequst(x)</code> is preferable to <code>x.submitViaHttp()</code></p>\n\n<p>Needless to say, these are not mutually exclusive. You\'ll probably actually have</p>\n\n<pre><code>networkConnection.submitHttpRequest(x)\n</code></pre>\n\n<p>in which you mix them both. The important thing is that you think about what parts are emphasized, and what you will be conveying to the future reader of the code.</p>\n'}, {'answer_id': 76997, 'author': 'easeout', 'author_id': 10906, 'author_profile': 'https://Stackoverflow.com/users/10906', 'pm_score': 2, 'selected': False, 'text': '<ol>\n<li><strong>Thing.DoSomething</strong> is appropriate if Thing is the subject of your sentence.\n\n<ul>\n<li><strong>DoSomethingToThing(Thing n)</strong> is appropriate if Thing is the object of your sentence.</li>\n<li><strong>ThingA.DoSomethingToThingB(ThingB m)</strong> is an unavoidable combination, since in all the languages I can think of, functions belong to one class and are not mutually owned.  But this makes sense because you can have a subject and an object.</li>\n</ul></li>\n</ol>\n\n<p>Active voice is more straightforward than passive voice, so make sure your sentence has a subject that isn\'t just "the computer".  This means, use form 1 and form 3 frequently, and use form 2 rarely.</p>\n\n<p>For clarity:</p>\n\n<pre><code>// Form 1:  "File handle, close."\nfileHandle.close(); \n\n// Form 2:  "(Computer,) close the file handle."\nclose(fileHandle);\n\n// Form 3:  "File handle, write the contents of another file handle."\nfileHandle.writeContentsOf(anotherFileHandle);\n</code></pre>\n'}, {'answer_id': 77014, 'author': 'Nikolai Prokoschenko', 'author_id': 6460, 'author_profile': 'https://Stackoverflow.com/users/6460', 'pm_score': 0, 'selected': False, 'text': "<p>Even in object oriented programming it might be useful to use a function call instead of a method (or for that matter calling a method of an object other than the one we call it on). Imagine a simple database persistence framework where you'd like to just call save() on an object. Instead of including an SQL statement in every class you'd like to have saved, thus complicating code, spreading SQL all across the code and making changing the storage engine a PITA, you could create an Interface defining save(Class1), save(Class2) etc. and its implementation. Then you'd actually be calling databaseSaver.save(class1) and have everything in one place.</p>\n"}, {'answer_id': 77091, 'author': 'Daniel', 'author_id': 13615, 'author_profile': 'https://Stackoverflow.com/users/13615', 'pm_score': 0, 'selected': False, 'text': '<p>I have to agree with <a href="https://stackoverflow.com/users/10906/kevin-conner">Kevin Conner</a></p>\n\n<p>Also keep in mind the caller of either of the 2 forms. The caller is probably a method of some other object that definitely does something to your Thing :)</p>\n'}, {'answer_id': 77303, 'author': 'Tyler', 'author_id': 3561, 'author_profile': 'https://Stackoverflow.com/users/3561', 'pm_score': 1, 'selected': False, 'text': '<p>I agree with Orion, but I\'m going to rephrase the decision process.</p>\n\n<p>You have a noun and a verb / an object and an action.</p>\n\n<ul>\n<li>If many objects of this type will use this action, try to make the action part of the object.</li>\n<li>Otherwise, try to group the action separately, but with related actions.</li>\n</ul>\n\n<p>I like the File / string examples.  There are many string operations, such as "SendAsHTTPReply", which won\'t happen for your average string, but do happen often in a certain setting.  However, you basically will always close a File (hopefully), so it makes perfect sense to put the Close action in the class interface.</p>\n\n<p>Another way to think of this is as buying part of an entertainment system.  It makes sense to bundle a TV remote with a TV, because you always use them together.  But it would be strange to bundle a power cable for a specific VCR with a TV, since many customers will never use this.  The key idea is <strong>how often will this action be used on this object</strong>?</p>\n'}]
['https://Stackoverflow.com/questions/76812', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/337/']