Questions tagged [law-of-demeter]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
2 votes
2 answers
1k views

Law of Demeter and its applicability

Let's say I'd like to perform the following command: house.getFloor(0).getWall(WEST).getDoor().getDoorknob(); To avoid a NullPointerException, I'd have to do the following if: if (house != ...
q126y's user avatar
  • 1,713
35 votes
1 answer
8k views

Is this a good scenario to violate the Law of Demeter?

I have this code in some part of an application: long sum1 = new Multiples().ofAny(new long[] { 3, 5 }).until(32768).sum(); long sum2 = new Multiples().ofAll(new long[] { 3, 5 }).until(32768).sum(); ...
user avatar
14 votes
5 answers
4k views

According to Demeter's law, is a class allowed to return one of its members?

I have three questions concerning Demeter's law. Apart from classes which were specifically appointed to return objects - such as factory and builder classes - is it okay for a method to return an ...
user2180613's user avatar
  • 1,762
7 votes
3 answers
1k views

Does this violate the Law of Demeter?

Let's say I have a class SelectableEntity<T extends Entity> which has three methods, select, deselect, isSelected and count. To take a somewhat contrived example, let's say I'm building an ...
NRaf's user avatar
  • 301
4 votes
1 answer
442 views

Dealing with a large interface

I'm working on a program that solves a certain type of systems of equations. The main data objects are Equation, Variable, Solution. Then I have this interface, which represents all things that I want ...
Patrik Bak's user avatar