What is the role of a prosecutor and defense attorney?

What is the role of a prosecutor and defense attorney? If you were a defense attorney, you know that you cannot take every case to court. So how would you decide which cases to plea bargain with the prosecution and which cases to take to trial?