-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample05.ts
More file actions
36 lines (32 loc) · 1.06 KB
/
example05.ts
File metadata and controls
36 lines (32 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
interface MediaPlayer {
play(audioType: string, filename: string): void;
}
// Adaptee
class AdvancedMediaPlayer {
playFlac(filename: string): void {
console.log(`Відтворення FLAC файлу: ${filename}`);
}
playWav(filename: string): void {
console.log(`Відтворення WAV файлу: ${filename}`);
}
}
// Класовий адаптер
class MediaAdapter extends AdvancedMediaPlayer implements MediaPlayer {
play(audioType: string, filename: string): void {
if (audioType === 'mp3') {
console.log(`Відтворення MP3 файлу: ${filename}`);
} else if (audioType === 'flac') {
this.playFlac(filename);
} else if (audioType === 'wav') {
this.playWav(filename);
} else {
console.log(`Формат ${audioType} не підтримується адаптером`);
}
}
}
// Використання
const player: MediaPlayer = new MediaAdapter();
player.play('flac', 'audio.flac');
player.play('wav', 'sound.wav');
player.play('mp3', 'song.mp3');
player.play('aac', 'audio.aac');