Notice how the LoginPage violates this. It calls a new on User Repository. The
issue here is that LoginPage is breaking
a the Law of Demeter. LoginPage is asking for the Database even though it
itself has no need for the Database (This greatly hinders testability as
explained here).
You can tell since LoginPage does not invoke any method on the Database.
http://misko.hevery.com/2008/10/21/dependency-injection-myth-reference-passing/
Policy.CurrentPeriod().Renew()
...There are a couple of problems with this approach. First, I'm clearly violating the Law of Demeter. A method M of an object O should invoke only the methods of the following kinds of objects: itself, its parameters, any objects it creates or instantiates, or its direct component objects.
http://msdn.microsoft.com/en-us/magazine/dd419654.aspx - and goes on to explain how using
Policy.Renew() ; i.e. invoking on Policy as the
aggregate root is more expressive and less problematic.
No comments:
Post a Comment