There are different discussions about this topic in the Internet, but there does not seem to exist a standard solution that can be implemented without any hacks.
The way templates in WordPress are built and have been built since the beginning does not meet today's requirements of WordPress as a CMS anymore. I usually end up with a lot of procedural code in the more complex theme template files. One approach is to try to export as much functionality as possible into a separate class file.
I think WordPress needs to grow up here. One of the biggest drawbacks if you develop themes regularly.