Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm writing (in PHP) a client/proxy for a SOAP web service. The return types are consistently wrapped in response objects that contain the return values. In many cases this make a lot of sense - for instance when multiple values are being returned:

GetDetailsResponse Object 
    Results Object
        [TotalResults] => 10
        [NextPage]     => 2

    [Details] => Array
        [0] => Detail Object
            [Id] => 1

But some of the methods return a single scalar value or a single object or array wrapped in a response object:

GetThingummyIdResponse Object
    [ThingummyId] => 42

In some cases these objects might be pretty deep, so getting at properties within requires drilling down several layers:


And if I unwrap them before passing them back I can strip out a layer from consumers' code.

I know I'm probably being a little bit of an Architecture Astronaut here, but the latter style really bug me, so I've been working through my code to have my proxy methods just return the scalar value to the client code where there's no absolute need for a wrapper object.

My question is, am I actually making things more difficult for the consumers of my code? Would I be better off just leaving the return values wrapped in response objects so that everything is consistent, or is removing unneccessary layers of indirection/abstraction worthwhile?

share|improve this question
up vote 1 down vote accepted

I've found it's better to be as consistent as possible so any consumer services know what to expect, it'll also be faster, easier and less buggy for yourself to simply return a response object around whatever data you're sending.

On the consumer side they can always use local vars to cut down the depth:

$cont = $response->Details->Detail[0]->Contents;

In short: always do what will surprise your users the least, make it simple for them.

share|improve this answer
Thanks @SteB, that's sort of where I was leaning.... – cori Dec 18 '12 at 12:55

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.