How create Common Functions to be used in modules drupal 8

 

Create a  File in Utility.php in modulename/src/ folder 

/**
 * @file
 * Contains \Drupal\mymodule\Utility
 */
namespace Drupal\mymodule;


class Utility {

     public  function  get_settings() {
       $return = \Drupal::config('mymodule.settings');
       return $return;
    }

}

Use Utitlity in your other module file

create MycustomController.php // refer how to create controller