YLOD is a major hardware failure and there are several causes of it: overheating, bad power supply, critical HDD error, or a malfunctioned motherboard (which is what happened with my first one). Depending on what caused YLOD, you technically can fix it but it’s not guaranteed that it’ll last long after. It could be as simple as cleaning out all the dust inside the system, or as complicated as reflowing the motherboard.
As to how to avoid it, there’s no certain way but I suggest doing things like keeping the console dust free and in an open area, let it cool after few hours of gaming (give yourself a break too, unless you want poor eyesight like me), and unplug it when not in use. Saves energy, environment, and your console. These are not guaranteed method to prevent YLOD, but it’ll keep your PS3 in good condition.