Referring to the object model for Sharepoint, for sites, you start with SPWeb. If you want to program master pages through the object model, SPWeb has 2 properties for this – MasterURL and CustomMasterURL. Of course these are available in the Publishing architecture and in that architecture, can be changed in the UI also,

The MasterURL is the property which is used for the System Master Page – those pages like the Site Settings page and others which are not specifically content type pages on the site. The CustomMasterURL is the property that matches up with the Site MasterPage (in the MasterPage area of Site Settings for a Publishing environment). This is used in the Publishing environment for the content pages themselves.