How can the Database class be improved to follow best practices, such as using static methods for connection initialization and instance retrieval?

The Database class can be improved by using static methods for connection initialization and instance retrieval to encapsulate the database connection logic and make it more accessible. This approach follows best practices by promoting a clean and organized code structure.

class Database {
    private static $instance;
    private static $connection;

    private function __construct() {
        // Private constructor to prevent instantiation
    }

    public static function getInstance() {
        if (!self::$instance) {
            self::$instance = new self();
        }
        return self::$instance;
    }

    public static function getConnection() {
        if (!self::$connection) {
            self::$connection = new PDO('mysql:host=localhost;dbname=mydatabase', 'username', 'password');
        }
        return self::$connection;
    }
}