Thursday, 23 July 2015

Improving Code Reuse



Hey guys,
I am having a web service that returns an array object containing another three array objects let's say description, service, details. For the time being I only need the description. I am thinking of which way is more effective especially in terms of SOLID principles as well the self evident Do Not Repeat Yourself. My first scenario is having a method e.g. getDescription whereby I only return the description part. 
However I am also thinking about future modifications. In case I need service next time what should I do?

I need to go and create another getter e.g. getService. Normally I will be unit testing the method as a good coding principle. More time, therefore more effort. Either case I will be calling this method regardless on the side of the factory or controller.
From my perspective to make things simpler, I prefer returning the object fully including the three array objects where on the consumption side (controller), I can then specify which object I will need.
$webService->description;
Later on if I need the service part, I simply add the following:
$webService->service.

No comments:

Post a Comment