# About continuous extensions and retractions

I'm trying to prove the following: Let $X$ a topological space and $Z\subseteq X$ $\text{For every topological space } Y, \text{ and for every continuous function } f:Z\rightarrow Y \text{ exists } g:X\rightarrow Y$ continuous such that $g|_Z:Z\rightarrow Y$ is equal to $f$ if and only if exists $r:X\rightarrow Z$ continuous such that $r|_Z(x)=Id_Z(x)$ i.e., $\forall x\in Z: r(x)=x$.

My question is about my proof. Notice that the implication $\Leftarrow$] is easy because $g(x)=f(r(x))$ is the function we want.

The implication [$\Rightarrow$ is my problem. I have two ideas:

1.- If $\delta(Z)=\emptyset$, the proof is finished. Otherwise, We have that $\overline{Z}\cup \overline{X\setminus Z}$ is a closed finite cover of $X$. If I can make $r_1:\overline{Z}\rightarrow Z$ and $r_2: \overline{X\setminus Z}\rightarrow Z$ continuous functions such that are equal to the identity in $Z$, then, the proof is complete.

2.-Since $Z$ is a topological space itself (the topology of $X$ restricted to $z$), we define $r:Z\rightarrow Z$ as $r(x)=x$ for all $x\in Z$. By hypothesis, there exists a continuous extension $g:X\rightarrow Z$ such that $g|_Z(z)=r(z)=z$. So, the proof is complete.

I have some problems accepting my second proof. Is right?. The first idea I can't finish it.

NOTATION: $\delta(A)$ denotes the boundary of a set and $\overline{A}$ the closure of a set.

Hint: Apply the hypothesis to $Y=Z$, $f=\mathrm{id}$. You got it from here?