You should never, ever write this kind of code. If you discover it in a project, refactor it out as soon as possible.

A Necessary Evil

Sometimes service location is necessary to ensure that only the code needed is being loaded and executed. Routing to a controller based on the URL path is an obvious real world situation. We might have some routing code that looks like this: