Why must the domain be connected in this exercise? I am working on the following exercise:

Consider a holomorphic function $f$ with a connected domain and $Im(f) = 0$. Show that $f$ is constant.

I solved it in the following way: Recalling the Cauhy-Riemmann Differential Equations the we have that the partials of $Re(f)$ have to be zero. So said partials are constant and thus continuous, so we know that $f$ is differentiable and we can apply the Mean Value Theorem. 
But why is it required that the domain is connected? Could you explain?
 A: The mean value theorem does not apply when the domain is not connected.
Compare with the following example of real analysis (really the same is going on in the complex plane, but at this point you probably have a better intuition about real-valued functions): Define
$$f: ]-2,-1 [\cup]1,2[\to \mathbb{R}: x \mapsto \begin{cases}-1 \quad -2 < x < -1 \\ 1 \quad 1 < x < 1\end{cases}$$ 
Then $f' = 0$ but $f$ is not constant.
In other words, on each connected component your function must be constant, but this does not mean the function is constant everywhere.
A: Otherwise, let your domain be the union of the two disjoint open balls $B(1,1)$ and $B(-1,1)$. Define $f$ to be $1$ on one of the two balls and $-1$ on the other. Do you see an issue?
A: Take $U_1,U_2$ two disjoint connected open subsets of $\mathbb{C}$. The complex valued function $f : U_1\cup U_2 \mapsto \mathbb{C}$ defined by
$$f(z) = \left\{ \begin{array}{cc} 1 & \textrm{if } z\in U_1 \\ 2 & \textrm{if } z\in U_2 \end{array}\right.$$
is holomorphic, and not constant.
