Is it OK to choose a derailleur without taking into consideration the cassette that will be used with it and vice-versa?
It's best, though not always entirely necessary, that the number of speeds match. There are some cross-compatible options, but if you're unsure it's better to just stick with a derailleur and cassette that were designed to work together.
It's also important to consider the size of the cassette in comparison to the amount of chain slack that the derailleur is capable of taking up. A road derailleur will often not work with a mountain bike cassette because it can not take up enough slack to account for the size of a mountain bike cassette.
Generally speaking, a cassette and derailleur that are the same number of speeds, made for the same type of bike, and made by the same manufacturer will be just fine.
No. I made the mistake of buying a nice looking 8 speed SRAM derailleur, to find that my Shimano 8 speed gear shifters, were incompatible. ie One click of the shifter didn't move the derailleur the correct distance to change one gear on the rear 8 speed cassette