Does System.out.println violate the law of demeter?
If not, why?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Depending on view.
LoD: Yes, because it uses the console. Under LoD you can’t assume access.
LoD-F: Yes, because it uses more than one dot. The LoD-F states that in any method usage only the object may know the internal structure of itself.
IE
requires knowledge of the structure of system (that it has .out) to reach println(),
For System to not break LoD-F it would have to be
To break the formal rules down with example, println() (the method) may only access:
(I know, it’s a reversed reference here as the code should be the method calling it, but it actually swings both ways.)