There is no such thing as encapsulation in (La)TeX, but even if there was one it will still possibly present a problem due to the nature of author commands. What do I mean? As (La)TeX is essentially a mark-up language, if you were to develop a package to for example provide macros to markup exercises, in all probability at the user level, you want to offer a:
\begin{exercise}
…
\end{exercise}
type of commands rather than \begin{MXexercise}. However to minimize problems and clashes with other packages, package and class authors do use prefixes and the @ symbol. A great example is the LaTeX3 conventions although IMHO this conservative approach taken to the extreme can damage code readability.
TeX also has a grouping mechanism where you can define macros and other commands locally. Anything between a group is defined locally. For example:
\def\acommand{43}
\bgroup
\def\acommand{42}
In group \acommand
\egroup
Outside group \acommand
The above will print 43 outside the group, but 42 within the group. The \bgroup and \egroup are just longhand for {}. You can have as many nesting groups as you need with the same effect.
Good practice IMHO, is for packages to stay focused to a single purpose and minimize author commands. Internally they can use prefixes or suffixes to avoid clashes.
For class authors the class itself should load a set of recommended packages for its common usage and any patches needed be applied by the class. Some classes go to the other extreme (such as the KOMA and Memoir) and define their own packages or incorporate functionality in the main code.
I understand your pain as I have been a user of hyperref for a long time. However, clashes can easily be bypassed as follows:
\usepackage{packageA}
\let\oldcommand\culprit % command from package A causing errors in package B.
\let\culprit\undefined
\usepackage{packageB}
If you want to use the \culprit somewhere do the reverse letting.
exerciseit is often not done. You could "undefine" this environment/macro (there are no "variables" in TeX) using\let\exercise\relaxbetween the loading of the two packages. Also TeX is not meant as a modern programming language and should not be compared to one, IMHO. – Martin Scharrer Feb 13 '12 at 10:04