Open jeffkwoh opened 6 years ago
As such, would this circumvent LoD ? I.e. calling
g.doSomething()
no longer violates LoD.void foo(Bar b) { Goo g = b.getGoo(); koo(g); } void koo(Gar g) { g.doSomething(); }
My take (there are slightly different interpretations of LoD): This is still a violation of LoD (in spirit) if one class ends up knowing the internal structure of another. In practice, use LoD as way to minimize coupling between classes rather than a law that needs to be followed to the letter.
I see, understand prof @damithc , in the context of exams, however, how should we approach ambiguous cases like this
I see, understand prof @damithc , in the context of exams, however, how should we approach ambiguous cases like this
@damithc Sorry about the late reply, I missed it. Thank you for your response and clarification!
Hi all,
I have a few questions on the Law of Demeter.
Please find the formal definition for convenient reference: • The object O itself • Objects passed as parameters of m • Objects created/instantiated in m • Objects from the direct association of O
This was given as an example and
g.doSomething()
violates LoD.As such, would this circumvent LoD ? I.e. calling
g.doSomething()
no longer violates LoD.To extend on this, how does LoD apply to higher order functions?
In the code below
model.updateFilteredTaskList(task -> originalTasks.contains(task));
, specificallyoriginalTasks.contains(task)
is equivalent tomodel.getFilteredTaskList.contains(task)
, does this violate LoD?Do we have a general set of rules pertaining to how we evaluate Law of Demeter for higher order functions? Do we treat the anonymous lambda created, a
Predicate
as "Objects created/instantiated in m", then through passing final local variables into the anonymous lambda, are all of those local variables considered as "Objects created/instantiated in anonymous lambda" or "Objects passed as parameters of anonymous lambda".A second question would be using a wrapper to circumvent LoD.
This is similar to
Then calling methods on
originalTasks
.Is LoD circumvented here?
Thank you!