You are having a lucid dream, where although you are asleep, you are very much aware you are dreaming. In my opinion these are the best dreams because you can control the content and the direction of the dream. Our dreams are many times completing a cycle that ended abruptly, answering unanswered questions, reassuring and delivering messages to loved ones. This happens to both the person who is dreaming and the person(s) in the dream. The example that you gave, in your subconscious you were worried about your friend and he wanted to put your mind at ease , so he came back to tell you he was happy and enjoying the after life. Since that dream was as vivid as reality, you could have told him anything you wanted to because you were in control. There are classes that are offered that will give you the basic knowledge on how to interpret dreams and how to control them.