I am reading "Topology 2nd Edition" by James R. Munkres.
In this book, the author wrote as follows:
Definition. Given functions $f:A\to B$ and $g:B\to C$, we define the composite $g\circ f$ of $f$ and $g$ as the function $g\circ f:A\to C $ defined by the equation $(g\circ f)(a)=g(f(a))$.
$\,\,\,\,\,\,\,$Formally, $g\circ f:A\to C$ is the function whose rule is $$\{(a,c)\mid\text{For some }b\in B, f(a) = b \text{ and }g(b)=c\}.$$
I think the following definition of the composite of two functions is much easier than the above definition.
Definition. Given functions $f:A\to B$ and $g:B\to C$, we define the composite $g\circ f$ of $f$ and $g$ as the function $g\circ f:A\to C $ defined by the equation $(g\circ f)(a)=g(f(a))$.
$\,\,\,\,\,\,\,$Formally, $g\circ f:A\to C$ is the function whose rule is $$\{(a,c)\mid c=g(f(a))\}.$$
Why did the author define the composite of two functions as above?
Probably beacause he defines a function $f\colon A\longrightarrow B$ as a subset $f$ of $A\times B$ such that, for each $a\in A$, there is one and only one element $b\in B$ such that $(a,b)\in f$. So, the definition he gave for $g\circ f$ is appropriate for his definition of function.