I have three classes:
Client
Session
Socket
Both Session & Socket depeand on the Client to create both objects.
A Session depeands on a Socket and no sockets are created without a session.
Should the Client have a function that creates a Session pubically and a Socket privately?
Doesn't it violate the law of demeter?
EDIT:
Current ...
According to the Law of Demeter, can you call methods on returned objects?
E.g.
<?php
class O
{
public function m($http)
{
$response = $http->get('http://www.google.com');
return $response->getBody(); // violation?
}
}
?>
$http->get() returns an object. Does this count as an object created/instantiated wit...
Does anybody know of a tool that I could use with a C# application to find possible Law of Demeter violations? I know that it would give a lot of false positives, but I think it could still be useful. Especially during the early design process.
...
I'm using a tool to automatically generate a class representation of a hierarchically organized XML file. The XML file is a settings file my app need to be able to access (read-only).
If I pass in the top-level node (e.g., AppSettings) to a class that needs to access one or more settings, I can easily end up with code that looks somethi...
Here's a method in my Spring/Hibernate website's code that exemplifies my codebase:
public class UserVoteServiceImpl implements UserVoteService {
@Autowired UserRepository userRepository;
public static int getUserScore(long userId) {
return userRepository.findUserById(userId).getScore();
}
}
I believe that this method...
The LOD description I've seen (for example, Wikipedia, C2 Wiki) talk about not calling methods. To quote Wikipedia:
The Law of Demeter for functions requires that a method M of an object O may only invoke the methods of the following kinds of objects:
- O itself
- M's parameters
- any objects created/instantiated within M
- ...