to answer your actual question.
When the book says $*$ is defined to be that $g*g=e$ for all $g\in G$, the book is abusing language. That isn't the definition of $*$; it is a property (a very significant property) of $*$ but not the definition of $*$.
If $G$, the set, is $\{e,a,b,c,d,e,f,g\}$ for example we know that $a*a=e$ and $c*c = e$ but we don't know what $ab$ is equal to; It could by $ab = c$ or it could be $ab = f$. But it doesn't matter.
......
We can prove that for all $a,b \in G$ that whatever $ab$ is equal to, that $ba$ must also be equal to the same value.
Note that if $ab = k$ and $k*k = e$ we have $(ab)(ab) = e$. But we also have $(ab)(ba) = a(bb)a = aea =aa = e$. So we have both $(ab)(ab) = e$ and $(ab)(ba) = e$.
If we rely on the proof we should have proven earlier that inverses are unique that means that $ab = (ab)^{-1}$ and $ba = (ab)^{-1}$ so $ab = ba$.
.....
If we want to really convince ourselves and we don't mind reinventing the wheel:
$(ab)(ab) = e$
$(ab)(ab)(ba) = (ba)$
$(ab)a(bb)a = ba$
$(ab)aa = ba$
$(ab) = ba$
=====
The thing is that other than examples to teach the concept of groups the actual operation $*$ doesn't matter and we almost never define what $a*b$ is equal to. And if $ab = c$ or $ab=f$ it won't matter. That's just labelling. What matters is only certain properties.