How can the principles of Dependency Injection be applied to improve the design of PHP classes like Album and DB?

Issue: The classes Album and DB are tightly coupled, making it difficult to test and maintain the code. By applying the principles of Dependency Injection, we can decouple these classes and improve their design. PHP code snippet:

// Album class with Dependency Injection
class Album {
    private $db;

    public function __construct(DB $db) {
        $this->db = $db;
    }

    public function getAlbums() {
        return $this->db->query('SELECT * FROM albums');
    }
}

// DB class
class DB {
    public function query($sql) {
        // Database query logic
    }
}

// Implementation
$db = new DB();
$album = new Album($db);
$albums = $album->getAlbums();