An exercise about the Pasting Lemma. I have difficulty with the following exercise from Introduction
to Topology (by Tej Bahadur Singh)(Exercise 9 on p. 36):

Let $f: X\to Y$ be a function between topological spaces, and assume
that $A\cup B= X$, where $A-B\subseteq A^\circ$, and  $B-A\subseteq B^\circ$. If $f|_{A}$ and $f|_{B}$ (endowed with the relative
topologies)  are continuous, show that $f$ is continuous.

I tried to use the following facts (from the book mentioned above):
Definition (locally finite). A family $\{A_i\}$ of subsets of a space $X$ is called locally finite if each point of $X$ has a neighborhood $U$ such that $U\cap A_i\neq \varnothing$ for at most finitely many indices $i$.
(1) Let $\{U_\alpha\}$ be a family of open subsets of a space $X$ with $X = \bigcup_\alpha U_\alpha$. Then a function $f$ from $X$ into a space $Y$ is continuous if and only if $f|_{U_\alpha}$ is continuous for each index $\alpha$. (See Exercise 8 on p. 36)
(2)  If a space $X$ is the union of a locally finite family $\{A_i\}$ of closed sets, then a function $f$ from $X$ to
a space $Y$ is continuous if and only if the restriction of $f$ to each $A_i$ is continuous. (See Corollary 2.1.10 on p. 33)
Using the fact (1), we obtain that  $f|_{A^\circ\cup B^\circ}$ is continuous. Clearly,
$f|_{A\cap B}$ is continuous. Since $A-B\subseteq A^\circ$ and $B-A\subseteq B^\circ$,
$A^\circ \cup B^\circ \cup (A\cap B)= X$. But $A\cap B$ is not open, so I cannot use the fact (1) again, I have not idea   what to do next. Any ideas would be appreciated.
 A: Maybe using local continuity arguments will do it: if $x \in X=A \cup B$. Let $V$ be an open neighbourhood of $f(x)$.
If $x \in A^\circ$ then we can find an open neighbourhood $U$ of $x$ such that $U \subseteq A^\circ$ and $f[U] \subseteq V$. This follows from continuity of $f\restriction_A$ and the fact that an $A$-open subset of $A^\circ$ is open in $X$ too.
If $x \in B^\circ$ we’re done in the same way, mutatis mutandis.
And if $x \in A \cap B$ (but in neither interior), we find an $A$-open $U_1 = U’_1 \cap A$ (so $U’_1$ is open in $X$) and a $B$-open $U_2 = U’_2 \cap B$ (ditto) such that $f[U_1] \subseteq V$ and $f[U_2] \subseteq V$. Then we could hope that $f[U_1’ \cap V_1’] \subseteq V$ as well (though I don’t see yet why this would hold if we don’t somehow restrict the larger open subsets in $X$…).
Just a thought that might help. Or maybe use nets: if $x_i \to x$ then either the net is eventually in one of the interiors or it’s frequently in $A \cap B$ and a subnet in $A \cap B$ converges to $x$ and the image net to $f(x)$, but again we lose control over the other points again…
A: Of course $f$ is continuous in all points of $A^° \cup B^°$. Since $A^\circ \cup B^\circ \cup (A\cap B)= X$, it remains to show that $f$ is continuous in all points of $A \cap B$.
Let $x \in A \cap B$ and $V$ be an open neighborhood of $f(x)$ in $Y$. There exist open neighborhoods $U_A$ of $x$ in $A$ and $U_B$ of $x$ in $B$ such that $f(U_A) \subset V$ and $f(U_B) \subset V$. Choose open $W_A, W_B \subset X$ such that $W_A \cap A = U_A, W_B \cap B = U_B$. Define $W = W_A \cap W_B$. Then $W$ is an open neighborhood of $x$ in $X$. We have $f(W) \subset V$: Let $y \in W$. But $y \in A$ or $y \in B$, w.l.o.g. $y \in A$. Thus $y \in W \cap A \subset W_A \cap A = U_A$ and therefore $f(y) \in f(U_A) \subset V$.
