So I have a webservice that has something like a getAccount
where it would return an identifier to the account if it got it, else throw an exception. The client will always want to create an account if an exception is thrown with the same info the get is done with.
I am creating a convenience library for clients that will be handling all of the webservice calls inside so they don't need to know how to do the calls themselves.
What I am wondering is in this library if I were to create a getAccount(accountName)
that will get the account if it exists, and if it does not then create it and return the info, is that a bad thing to do? Should I leave it to the client to handle the exceptions or simply name it something like getOrCreateAccount? Does it matter?
Is it bad practice to create something in a get operation?
getOrCreateAccount
or similar. – Telastyn May 22 '12 at 19:08acquire
, likeacquireAccount
. It doesn't have an existing meaning in any major protocols that I have encountered, and it has an imperative ring to it that suits it well. "Do whatever you have to do to acquire one of these for me. Request it, build it, fake it, steal it, I don't care, just get me one or die trying." – Dan Ross Apr 17 '16 at 11:38getSomething()
is for getters, andsetSomething()
is for setters. Imo anything that does something more intellectual must be called something else, i.e.fetchSomething
,obtainSomething
,computeSomething
, ordoSomethingElse
etc. – ccpizza Oct 29 '16 at 13:23