
On Wed, 13 Apr 2022 at 02:00, Matsuoka Takuo <motogeomtop@gmail.com> wrote:
Thanks for your answer.
On Mon, 11 Apr 2022 at 00:46, malmiteria <martin.milon@ensc.fr> wrote:
There's a few problems, mainly, if you provide ProudGobelin and CorruptedGobelin as a lib author, you're very likely not to think of the HalfBreed use case, so the lib users wanting to create the HalfBreed class is bared from this solution, as it requires some work on ProudGobelin and CorruptedGobelin classes.
Actually, now I see. It's the lib author's fault. She went against DRY in defining CorruptedGobelin and ProudGobelin as unrelated subclasses of HighGobelin when they had a common structure, unless she intended to make things like the "failing" version of HalfBreed easier to create. Otherwise, I think she should have done as follows, and that's close to the solution I shared with you first. ``` class HighGobelin: def scream(self): print("raAaaaAar") class SpeakingGobelin(HighGobelin): def scream(self): self._speak() super().scream() def _speak(self): return class CorruptedGobelin(SpeakingGobelin): def _speak(self): print("my corrupted soul makes me wanna scream") class ProudGobelin(SpeakingGobelin): def _speak(self): print("I ... can't ... contain my scream!") ``` Best regards, Takuo