When it comes to pairing specific ingredients, the general thinking seems to be that ingredients that share "flavour notes" in significant quantity will go well together.
In practice it goes much deeper than that, because in addition to taste, foods have very specific and recognizable aromas which affect the perception of flavour; wine is mostly sweet and sour, but you wouldn't substitute ordinary grape juice for it; the aroma of the alcohol is unmistakable, and even between different wines you will have varying levels of "fruitiness" or "woodiness".
But let's start with tastes:
Chocolate and coffee go well together because they share characteristic bitter notes. The roasting of the beans also makes a difference; the pairing works best when the roasting is enough to thermally degrade the bitterness without losing too much sweetness due to caramelization. This emphasizes the sweetness and de-emphasizes the bitterness and acidity of the coffee, making it closer to the flavour profile of chocolate.
A traditional stock combines a mirepoix (onions, carrots, celery) with meat (well, bones), both very high in umami. The end product may have varying notes of bitterness or saltiness from the vegetables but is basically one huge kick of umami. A lot of people also enjoy peanut butter and bacon together, which combines the significant umami and saltiness in both foods.
Beets and sour cream are a traditional (or so I'm told) Polish dish, both obviously sharing strong sour notes. Often chives are added, which are mildly pungent in nature and pungency tends to go with sour or bitter (since it is created by sulfur which is perceived as sour, bitter, and also "metallic").
This tends to work reasonably well for basic pairings, but another very strong element of this is balancing all of the different flavours in a dish.
Peanut butter and jam don't seem to have much in common, flavour-wise. But when you combine them together in a sandwich you have the high umami and saltiness of the peanut butter, the sweet and slightly sour notes of the jam, and the hints of bitterness and/or sourness in the bread. Together you have strong notes of all five tastes and the result is appealing to most people.
Five Spice is usually a mixture of cinnamon (sweet), star anise (mildly sweet and bitter), fennel (mildly sweet and fairly savoury), ground cloves (pungent and somewhat bitter), and Szechuan peppercorns (salty and pungent with a sour aftertaste). The quantities are generally adjusted to balance out the tastes; for example, fennel is the only really savoury ingredient so Five Spice tends to have more of that than other ingredients. Anyway, this is used all over Chinese cuisine as a sort of "wonder spice".
A really good roast chicken starts off high in umami and is then brined (salty), buttered (sweet), and roasted which involves the Maillard reaction (bitter). This is missing sour, which is why a lot of cooks will throw a few lemon slices in there.
But truthfully, even though this all sounds plausible, it's really so much more complicated than that. Even though there's some science at work here, the five tastes are a little like the four elements or humours; it's an almost archaic way of thinking about food chemistry, because our mouths and noses can detect so much more than that.
If you want to see just how little we actually really know about flavour today, check out They Go Really Well Together on Khymos, linked to from one of the related questions. There you'll see totally nonsensical combinations like chocolate and garlic or mint and mustard that actually - with the right preparation of course - produce pretty pleasant flavours/aromas.
The truth is people are still gathering data on this and we don't really know, exactly, what makes some flavours work together. At least we're starting to approach this scientifically and actually experiment and document this stuff, but there's not enough data to form a coherent theory yet. Check the answers to my question about flavour pairings and the other question on pairing resources if you want detailed data on which flavour pairings can "work", although you might not get much of an explanation for why.
Harold McGee, in On Food and Cooking, is very detailed in his explanation of how cheese "works". He describes three stages.
In the first stage, lactic acid bacteria convert milk sugar into lactic acid. In the second stage, which overlaps with the first one, rennet (an extract of calf stomach - or, to be more precise, chymosin, a protein found in this extract and now also obtainable from yeasts and the like) curdles the casein proteins and watery whey is drained from the concentrated curds. And finally, in the third stage, the cheese ripens, and a whole host of different enzymes do all sorts of things to flavour and texture.
According to McGee,
Acid and Rennet form very different kinds of curd structures -- acid a fine, fragile gel, rennet a coarse but robust, rubbery one -- so their relative contributions, and how quickly they act, help determine the ultimate texture of the cheese.
He goes on to describe how mostly acid coagulation leads to softer cheeses and mostly rennet-based coagulation leads to firmer curds and harder cheeses.
Draining of the whey also strongly affects the final texture, as Sobachatina points out in her excellent answer. Pressing firmly expels much whey and thus leads to a harder cheese; softer cheeses are just allowed to drain some whey by gravity. But there's another important factor here: heat. Some cheeses are "cooked" in their whey at this stage, to a temperature as high as 55C (130F) for a rock-hard Parmesan or about 38C (100F) for a somewhat softer Tommes, and this expels even more whey from the curd particles (and, of course, also affects flavour).
At this stage, salt is also added. Salt draws some moisture out of the curds as well and is a catalyst for the denaturing of casein, thus reinforcing the protein structure.
McGee also discusses aging of cheese at some length, but he doesn't really touch on the effect of aging on the structure of cheese. That effect is certainly there; a very young Gouda cheese is almost as soft as a Camembert, whereas a very old one gets close to Parmesan hardness (if it doesn't crumble to dust). I imagine that this is due to some moisture escaping the cheese, but also due to the fact that the protein networks keep growing more and more interconnected as the cheese ripens.
Best Answer
Three factors influence how well cheese melts:
The amount of moisture,
The amount of fat,
How it was set.
The meltiest cheeses have a lot of moisture and fat and were set with rennet and not acid. Both moisture and fat leave space between the casein proteins that allows them to move. Otherwise they are packed together and don't flow as well.
Aged cheeses have lost more of their moisture to evaporation. This means that they have to been heated to a much higher temperature before they will melt.
To quote Harold Mcgee: "Melting behavior is largely determined by water content. Low-moisture hard cheeses require more heat to melt because their protein molecules are more concentrated and so more intimately bonded to each other." (On food and Cooking, 64).
Aged cheeses with a high fat content will often leak some fat when they finally do melt- making an oily mess. J. Kenji Lopez-Alt had some good suggestions for dealing with this problem.
Acid set cheeses, such as Indian paneer and latin Queso Blanco, don't melt much when heated dry because the acid denatures the casein in such a way as to cause it to bind more tightly.(although they will dissolve into hot liquids sometimes.)