diff --git a/python_3_oop/chapter03/audiofile.py b/python_3_oop/chapter03/audiofile.py index d1856ba..927a276 100644 --- a/python_3_oop/chapter03/audiofile.py +++ b/python_3_oop/chapter03/audiofile.py @@ -1,4 +1,5 @@ # small example for inhiterance with polymorphism +# and duck typing as mostly better alternative class AudioFile: @@ -29,4 +30,15 @@ class OggFile(AudioFile): ext = "ogg" def play(self): - print("Playing {} as ogg".format(self.filename)) \ No newline at end of file + print("Playing {} as ogg".format(self.filename)) + + +class FlacFile: + + def __init__(self, filename): + if not filename.endswith(".flac"): + raise Exception("Invalid file format") + self.filename = filename + + def play(self): + print("Playing {} as flac".format(self.filename))