The hips are ball-and-socket joints. Here is a picture of the hip joint on the model. You can see from the pictures and x-ray above that the pelvis is a big, bony box that looks a bit like a window frame. This picture shows better the nice round socket (obviously there is one on either side). The thigh bones (femurs) each have a large, round ball at the top end, which perfectly fit into the round sockets in the pelvis.
You can also see that the socket is not so deep that it completely holds the ball. If it was, we wouldn't have the great range of circular motion that we do in the hip. The socket takes in about half of the ball. This fortunate arrangement allows the male dog to lift his leg to pee on a tree, and allows for full extension and thrust backward when the animal is at a dead run.
If there were no other structures to hold this joint together, the balls would just fall out of the sockets, so we need other things. There is a ligament that runs from the end of the ball to the center of inside of the socket. In the picture above it is an elastic cord, but in real life it is a relatively un-stretchy ligament, and is one of the reasons that it's hard to dislocate the hip. There are also a lot of muscles that attach to the top of the femur from the pelvis and back. They help to move the leg, but also hold the hip in.
Obviously there are lots of areas for potential problems. A small change in one thing, like the rate of bone growth or whether a ligament is tight enough, affects another part, which affects two more, and the problem grows. Before you know it, the dog is in big trouble from what seems like a small problem.
More big words that will impress your vet
Anatomists like to call round things on the ends of bones heads', and since this one is on the femur it got called the femoral head. The socket in the pelvis is called the acetabulum (ass-e-TAB-you-lum). When we talk about the ball and socket, we are more correctly discussing the femoral head and how it fits into the acetabulum. There. Now you can sound all educated and fancy-like.