Several reasons. Yes, one of them is because of obscurity—have to throw that in before people jump down my throat.
But Classic Mac OS had several viruses...over 100, if I remember correctly. OS X has been around as OS X for the last 6 years and it was around as Rhapsody, OpenStep and Nextstep for another 15 years before that and it still hasn't had a virus.
OS X is designed to be secure. The default user in Windows is basically given carte blanche to the entire system. They can delete things, move things, change things without any problem, and any software loaded under this default user has the same abilities, which is why viruses work on Windows. Also, throughout the years Microsoft has made all sorts of kludges to the system to keep it backwards compatible and to add new features, and all of that sloppy code has combined together to make many many leaks in the system where things can get in.
OS X on the other hand does not give the user access to everything. The "root" account, the account that has carte blanche, is turned off on OS X by default and the Administrative accounts are not allowed to touch the system or other important files. Also, before any software is allowed to do anything the Admin must give it permission by inputting his password. The occasional trojan has gotten through on OS X because people can be duped into inputting their password, but the most one can do is delete the content of your home folder. The computer itself will still run without a problem.
Before a true virus ever comes to OS X someone has to find a way past the security. Someone has to find a way to give the virus root access while still running under the the default account, and so far no one has.
One day someone will, and Apple will most likely have a security update out within a couple days of it, unlike MS which generally chooses to address things like that in Service Packs.