DEV Community

Discussion on: Don't return associative arrays!

Collapse
 
aleksikauppila profile image
Aleksi Kauppila

Thanks for your comment!

Frankly, i'm not really sure if it's that good design to return these sort of reports. To me that means the service has knowledge that there's is some sort of UI where those values are somewhat important. I left myself a backdoor by giving SenderReport a method to print itself which gives the object some behaviour.

I do however think that it's useful to give data some context by encapsulating it into an object. It allows us to fall back on sane defaults and handle other data related issues in a very limited scope. After all you can't tell data to do anything. With objects you can.

I can't say i have much experience about this, but just a hunch that a system can be more robust when the focus is not on what kind of data is processed but what kind of services objects provide for each other.