Can theme function be implemented in a module file? For example, in bartik theme, it has

/**
 * Implements theme_menu_tree().
 */
function bartik_menu_tree($variables) {
  return '&lt;ul class="menu clearfix"&gt;' . $variables['tree'] . '&lt;/ul&gt;';
}


Is there a way to override it via .module file?
Modules can create the initial implementation of a theme function but they can't override existing theme functions.

Modules do have one option available which should be used as a last resort: hook_theme_registry_alter. I would advise against every using this, since it will lead to code that's harder to maintain, and make it hard on those needing to theme the site. Also modules should be design never worry about theme functions of other modules, that is why we have themes. With that being said, if you change the theme registry you can change which function will be used regardless of what is normal practice, meaning that you will overwrite functions defined in themes. You can however use logic to prevent that from happening, but it can easily lead to many WTF moments, especially 6-12 months from now when you or some one else need to maintain the site.