111 reputation
2
bio website
location United States
age 44
visits member for 2 years, 1 month
seen Nov 17 at 17:32

Dec
12
comment Architecture Best Practice (MVC): Repository Returns Object & Object Member Accessed Directly or Repository Returns Object Member
@MattDavey - I agree with you 100% not to let a question of this nature block progress on a project. However, not to note it and offer it up to your peers for discussion typically means that the question will remain for the next project. And even that wouldn't be so bad if it was only one question, but each question is just... one question. Lots of those in a pile? Code which is... untestable, unflexible, unmaintainable and developer hostile. :)
Dec
12
comment Architecture Best Practice (MVC): Repository Returns Object & Object Member Accessed Directly or Repository Returns Object Member
@TomB - It isn't really a question of domain logic here - my choice of $validation_date for the example is incidental. Assume that the user merely wants to retrieve an arbitrary piece of user data (birthday if it's easier) via an AJAX call. The flow is then going to be as you described it, but only to a point: controller gets $id, pulls the user from the repo... then what? Pass it to a model method simply to extract a date? Really?! So the question is as asked - ideally, should the controller access the property directly, or should a repository method handle that?
Dec
12
comment Architecture Best Practice (MVC): Repository Returns Object & Object Member Accessed Directly or Repository Returns Object Member
@MattDavey - A product which is untestable, unflexible, unmaintainable and developer hostile. I'll take the 'architectural principles' agony over that sort of agony any day...
Dec
12
awarded  Student
Dec
12
comment Architecture Best Practice (MVC): Repository Returns Object & Object Member Accessed Directly or Repository Returns Object Member
@Tom B - And if the $user_id comes from $_GET['user_id']? :)
Dec
12
comment Architecture Best Practice (MVC): Repository Returns Object & Object Member Accessed Directly or Repository Returns Object Member
@onlineapplab.com - That would certainly solve the issue of Encapsulation. The Law of Demeter & the Single Responsibility Principle would still be in tension between the approaches, however.
Dec
12
comment Architecture Best Practice (MVC): Repository Returns Object & Object Member Accessed Directly or Repository Returns Object Member
@Simon Whitehead - you've obviously been hanging around the wrong PHP programmers... :) Seriously, though, these concerns aren't all that uncommon - PHP has matured significantly with 5.3 & 5.4 and we're seeing a lot more architectural thought perhaps once reserved for enterprise applications (and therefore other languages) going into PHP applications.
Dec
12
comment Architecture Best Practice (MVC): Repository Returns Object & Object Member Accessed Directly or Repository Returns Object Member
@AakashM - Fair question on the surface, though ideally if I wanted to get at an object's members, I would utilize dependency injection and pass in the object as a parameter. The question only exists in this case because that isn't possible.
Dec
12
awarded  Supporter
Dec
12
comment Architecture Best Practice (MVC): Repository Returns Object & Object Member Accessed Directly or Repository Returns Object Member
@jgauffun - arnaud is correct - in this case user/account are essentially synonymous.
Dec
12
comment Architecture Best Practice (MVC): Repository Returns Object & Object Member Accessed Directly or Repository Returns Object Member
I find it interesting that this answer was down-voted. I take dependency injection as pretty much a given (though admittedly in this partially contrived exampleI was assuming injection of the user repository rather than the user object itself). That approach may not be possible here, as the code in question exists at the 'outermost' level, the controller - my IoC container can inject the repository but not a specific object. The basis of the question then is how to get at the property once the injected repository is used to retrieve the user object. My upvote brings you to zero - thanks!
Dec
12
asked Architecture Best Practice (MVC): Repository Returns Object & Object Member Accessed Directly or Repository Returns Object Member