macs stand the test of time better than other, yes, but 90% of the time, when something goes wrong, you are much more likely to be forced to replace your whole computer rather than just changing a part... and given their price, i wouldn't consider it as being cheaper.
But basically if you want your computer to last long, always make sure it stays cold, if you can feel it's hot with your hand, something is wrong, the more hot your computer becomes, the quicker it will be "used".
make shure it has space to breath fresh and clean air, avoid using it near the floor ( 20cm hight is more dirty, dunno the word in english, all those little grey things ), and from time to time don't forget to open your computer and clean the ventilator. If it's a laptop avoid closing the screen on the keyboard. Don't shut them down brutally, leave some ram free... It's better to use your laptop flat rather than inclined, for example on the train or on your knees, with time some parts can become to move a little, nothing big but you can have problems if the hard drive works a lot a this moment ( and anyway having a laptop on you is bad for fertility ).