This is a classic example of a genre parody. It's not one of those jokes-coming-at-100mph kind of spoofs (such as Blazing Saddles), it simply plays everything by genre rules. It shares this with the 1939 version of Destry Rides Again, but it goes much further in exhibiting the hilarious potential of the genre by just slightly exaggerating the kind of improbable situations classic Westerns so often throw at us.
To appreciate this film properly you need to be familiar with the classic Western genre, mostly to understand how the genre works when played straight but you may also recognise some movie references.
The cast is absolutely marvellous, James Garner is a commanding lead, Jack Elam has never been better, and there are first-rate character actors for all the supporting roles. Especially Harry Morgan and Walter Brennan are excellent in roles very similar to ones they played straight in High Noon and My Darling Clementine, respectively.