I am trying to prove that the connected sum of surfaces is a surface.
My definition of surface is: A topological space locally homeomorphic to $\mathbb{R}^2$, second countable, Hausdorff and connected.
Let $S_1$, $S_2$ be surfaces, $D_1\subset S_1$, $D_2\subset S_2$ with $D_i$ homeomorphic to a closed disk of $\mathbb{R}^2$. Let $U_i$ be an open set such that $D_i\subset U_i$ and it is homeomorphic to $\mathbb{R}^2$. Then $\partial D_i$ is homeomorphic to $S^1$. Let $\varphi:\partial D_1 \longrightarrow \partial D_2$ be a homeomorphism.
We consider the disjoint union $(S_1\setminus \text{Int}(D_1))\cup(S_2\setminus \text{Int}(D_2))$ and the equivalence relation induced by $\varphi$, $S:=[(S_1\backslash \text{Int}(D_1))\cup(S_2\backslash \text{Int}(D_2)) \;/\sim_{\varphi}]$ and we call $p$ the quotient map.
Defining $U=S_1\setminus D_1$, $V=S_2\setminus D_2$, then $p(U)$ and $p(V)$ are homeomorphic to $U$ and $V$. This implies that $p(U)$ and $p(V)$ are locally homeomorphic to $\mathbb{R}^2$, Hausdorff and second countable.
What is the easiest way of "gluing" $\partial D_1$ and $\partial D_2$? I was thinking about defining $W_i=U_i\setminus D_i$ and then using $p(W_1\cup W_2)$ to make $S=U\cup V\cup p(W_1\cup W_2)$, but I got stuck.
You will get an easier gluing if you use a collar neighborhood. The two loops are bounding a disk, hence have a small neighborhood $T,S$ such that $S^1 \times (-1,1) \to T \subset S_1$ and $S^1 \times (-1,1) \to S \subset S_2$ isomorphisms (in the smooth case diffeomorphism and you get a smooth structure). You think of $S^1$ as the boundary of the disks.
Now my professor (Kreck) used to say: If you glue things together in your basement, you don't want to glue them together at their boundary, you prefer that they overlap, so that the gluing is stronger.
So this is the idea here. After taking out the disks, you still have collar neighborhoods of the loops by restricting the above maps: $S^1 \times (-1,0] \to T'=T-int D$ etc. This will give you an open set to glue the surfaces together. Then you will do everything easily by cases: every point lies either in one surface (together with a neighborhood) or it lies in the gluing part (together with a neighborhood). From here on it will be very easy to finish your exercise.
This in fact primarly answers the question: "what's the easiest way of gluing". But it really helps for the rest!