I thought it is unavoidable, you must do constant redesigning.. how you can avoid that?
This take a long time to master, in other words, it's a skill you aquire with time, and a lot of programming.
Also, some planning really dosen't hurt.
You could start by making XML graphics stuffs(i forgot how it's called) to see how the pieces fit togheter, build some interfaces before actually start coding something ect.
Anyway, most of the time, you first draft of the code will require a recode or two, but that's mostly matter for big projects.