Many people have little to no idea about how to behave properly in cafes or restaurants, and often their behaviour creates an unpleasant environment for the people they're with, other patrons, and the employees.
Behaviour in general
You are in someone else's workplace. Think about your own job, and how dealing with rude patrons/customers/members of the general public affects you. Treat the staff the way you would like to be treated at your place of employment. Smile at them, and engage in small-talk. Don't unload your problems on them, they don't get paid enough to be your psychologist.
If the cafe or restaurant is close to you, and you plan on becoming a regular there, it is worth your while to put in extra effort to be nice to the staff. If you go out of your way to be pleasant and easy to deal with, not only will you have the satisfaction of knowing you've made another human being's life less miserable, you will also reap the benefits of being a valued regular. This relationship takes a while to build up, but it's definitely worth it.
Remember that waiters and baristas aren't paid very highly, and that their job requires them to be on their feet all day.
You should never, ever expect to take less than half an hour for a coffee and cake (from start to finish, not just waiting to order), and no less than 45 minutes for basic cafe food, and no less than an hour in a restaurant. If you don't have the time, don't order. Obviously, some places are much faster than this, but you won't know that unless you've been there a few times before. Err on the side of caution, rather than ordering a large meal on your 15 minute break and getting angry at the waiter when it's not there in time.
Likewise, use a friendly tone of voice when talking to your waiter. A waiter is not your indentured servant. It's true that he or she should behave in a polite manner, but this is a two-way street. The customer is not infallible. If you're in there, ordering a coffee and a sandwich, don't act as though you should be treated like you're staying in the penthouse at the Hilton. Always say "please" and "thank you", like your parents taught you.
Don't make assumptions or judgements about your waiters. Don't feel superior to them simply because they work in a cafe or restaurant. In Sydney, a great many people working in cafes or restaurants are university students. Maybe your barista is completing a PhD. Aside from the fact that it's totally inappropriate to make judgements about someone's worthiness due to their job, for many baristas and waiters this job will not be their career, but something to pay the bills between acting gigs, or to top up their Youth Allowance. You don't know what your young waiter will achieve in his or her life, so don't act as though you are superior to them. Never, ever, openly put them down because they work in a cafe.
Realise that the waiter or barista has little control over many things at their place of work. The number of toilets, menu changes, prices etc are all things that are not the fault of the waiter, so don't complain to them. There's nothing they can do about it.
The always-entertaining Graveyard Barista has written about bad cafe behaviour from the perspective of a waiter. Here are his top ten pet hates, Part One and Part Two.
If you are in an establishment where a waiter will seat you, there will generally be a sign at the front. It is incredibly rude to seat yourself if this is the case. Otherwise, find a table for yourself, but please make sure you take a table with an appropriate number of seats for your party. It's impolite for two people to take up a table which could seat six, unless there's really no other option.
Getting the waiter's attention
Sometimes this can take a while, especially if the cafe or restaurant is very busy. Appropriate methods of getting a waiter's attention include sitting up straight and trying to make eye contact, inclining one's head, smiling, or saying "excuse me" in a friendly tone if they're right next to you (but not if they're in the middle of taking another table's order). The last one should really only happen if you've been waiting for a while. Don't make a big deal about how long you've been waiting - they're probably already aware and if the place is understaffed, or if it's a busy time, there's not much they can do. Be reasonable.
Don't ever call over a waiter from across the room, click your fingers or tap your glass with your fork. This sort of behaviour is completely unacceptable.
Sending back an incorrect order or bad food
If your order is incorrect, or worse, there's someone actually wrong with the food, feel free to send it back. The waiters will not be angry at you for wanting to eat what you ordered. I feel it's best to check with the waiter that your order is correct when you're ordering, but make sure you do this politely. Saying "Can you read back the order to me so I can make sure I haven't forgotten to order anything" is a lot better than "Read that back so I know you haven't made any mistakes". After all, mistakes in ordering can come from both sides, and it's easier to check this before the food is made, rather than afterwards.
However, if a mistake is made, or the food is bad, there is never any cause to make a scene. Give them the benefit of the doubt - things go wrong in all workplaces, especially when everyone's busy. Get the attention of the waiter and quietly explain the problem to them. If you've just gotten the wrong order, don't start eating it - it may be for another table. Don't scream or threaten anyone, it's not all a big conspiracy on behalf of the waiters to make your dining experience less enjoyable. You can get the problem fixed without being a bad customer.
Behaviour towards other customers
Remember that you're not the only customer in the place (unless you are, of course). Don't discuss other patrons, or if you must, be quiet and discreet. Avoid talking to other patrons at a restaurant. In a cafe, this is slightly relaxed, but use your common sense to work out when it's appropriate to say something and when it isn't. Don't try to strike up conversations with other people. Merely commenting that you love their hat, or that their baby is adorable, is completely fine, but it's inappropriate to try to make a new friend. This might be the only time they get to themselves all day.
Avoid hitting on people, unless you've been making flirty eye-contact for a while.
Tipping, in Australia, is a complicated business because there's no set amount for anything. We're only just developing a tipping culture, and many people have mixed feelings about it.
Tipping depends on your experience. If the waiter or barista does their job, serves you in a timely fashion, is polite and the food is good, it's appropriate to tip. 10% is a good standard to work from. If you've recieved any kind of special treatment, for example they've kept the kitchen open a bit longer for you, tip a bit extra. If you're a regular, tip well, it will definitely come back to you. I make a habit of tipping quite well whenever I'm flush with cash at my local cafe, and I always receive excellent service and occasionally, fun extras such as a free slice of cake. Don't expect this kind of thing, just appreciate it when it comes to you.
Tipping recognises that the waiters themselves work extremely hard. It is an extremely tough job, and it's often paid quite poorly. By tipping someone, you are acknowledging that they are a person, and that they do a good job. It's a way of thanking them directly.
Of course, if you've received poor service, don't feel obliged to tip. If you're really broke, give something, maybe 20c if you've bought a coffee, but just enough so it's clear you appreciate the effort.
Above all, just remember that your waiter or barista is a human being, not a slave. Be understanding and forgiving of small mistakes. You are not the Queen of Sheba, especially not if you're just getting a $3 latte at your local cafe.