-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadapter.py
More file actions
30 lines (20 loc) · 781 Bytes
/
Copy pathadapter.py
File metadata and controls
30 lines (20 loc) · 781 Bytes
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
from abc import ABC, abstractmethod
class MediaPlayer(ABC):
@abstractmethod
def play(self, filename):
pass
class OldAudioPlayer:
def play_audio_file(self, filepath):
print(f"Воспроизведение через OldAudioPlayer: {filepath}")
class AudioAdapter(MediaPlayer):
def __init__(self, old_player: OldAudioPlayer):
self.old_player = old_player
def play(self, filename):
print("[Адаптер] Преобразуем вызов...")
self.old_player.play_audio_file(filename)
old_player = OldAudioPlayer()
adapter = AudioAdapter(old_player)
adapter.play("song.mp3")
# output:
# [Адаптер] Преобразуем вызов...
# Воспроизведение через OldAudioPlayer: song.mp3