Why does reflection from a denser medium cause a phase difference of $\pi$? I was going through a portion speaking about interference due to thin films. It says that a phase difference of pi occurs in the reflected system, due to reflection from the surface of a denser medium but gives no reason to it.
Any help is appreciated.
 A: Not all reflections have $180^{\circ}$ phase change, it depends on whether it's free end (denser to less dense medium) or fixed end (less dense to denser medium).
Water waves reach the shore cliff do reflect on the same phase so the amplitude near the wall is reinforced by reflection.  The particles are free to moving up and down at the wall and hence the momentum is preserved in direction.
However for fixed end, the particles are locked in position, the reaction force acts in opposition direction so that the momentum flips its direction.
In thin-film interference, you need to treat the phase change carefully at the interface.
A: This is more of a teaching example than a complete explaination.
Tether a rope to a doorknob. Stretch it out horizontally and snap an upward pulse in the direction of the doorknob. When that pulse reaches the doorknob, a more dense medium compared to the air, it will be inverted upon reflection. The rope exerts an upward force on the doorknob when it arrives. By Newton's Third Law, the doorknob exerts an equal and opposite force on the rope, thus the inversion.
The more difficult question is why the reflection from a less dense medium is not inverted. I'm no help with that. My description above is more for help remembering which boundary inverts than why.
A: The vector electric field tangential to the interface must be continuous across the interface. This is a simple consequence of the Faraday-Maxwell law.
In the denser medium, the electric field is in phase with the incident wave but weaker. To make the vector electric field continuous across the interface, the reflected electric field must point in the opposite direction to the incident electric field, so that their sum can equal the transmitted electric field.
