Architecture Best Practice (MVC): Repository Returns Object & Object Member Accessed Directly or Repository Returns Object Member
Posted
by
coderabbi
on Programmers
See other posts from Programmers
or by coderabbi
Published on 2012-12-12T05:38:32Z
Indexed on
2012/12/12
11:18 UTC
Read the original article
Hit count: 250
Architecturally speaking, which is the preferable approach (and why)?
$validation_date = $users_repository->getUser($user_id)->validation_date;
- Seems to violate Law of Demeter by accessing member of object returned by method call
- Seems to violate Encapsulation by accessing object member directly
$validation_date = $users_repository->getUserValidationDate($user_id);
- Seems to violate Single Responsibility Principle as $users_repository no longer just returns User objects
© Programmers or respective owner