Let's start with Wikipedia:

> 
> More formally, 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:
> 
> 
> 1. O itself
> 2. m's parameters
> 3. Any objects created/instantiated within m
> 4. O's direct component objects
> 5. A global variable, accessible by O, in the scope of m
> 
> 
> 

Rule 1:

```
public class ClassOne {

    public void method1() {
        method2();
    }

    public void method2() {

    }
}

```

Rule 2:

```
public class ClassOne {

    public void method1(ClassTwo classTwo) {
        classTwo.method2();
    }
}

class ClassTwo {

    public void method2() {

    }
}

```

Rule 3: 

```
public class ClassOne {

    public void method1() {
        ClassTwo classTwo = new ClassTwo();
        classTwo.method2();
    }
}

class ClassTwo {

    public void method2() {

    }
}

```

Rule 4 (thanks @juharr):

```
public class ClassOne {

    private ClassTwo classTwo;

    public void method1() {
        classTwo = new ClassTwo();
        classTwo.method2();
    }
}

class ClassTwo {

    public void method2() {

    }
}

```

Rule 5:

```
?

```

Can anyone help me with Rule 5?

---

And doesn't Law of Demeter imply that chaining is bad?

```
User.getName().getLastName();

```

This leads to high coupling.

---

Isn't "Tell, don't ask" a similar principle? 

So is this everything? Am I wrong about something? How can you obey Law of Demeter?