
Matsuoka Takuo writes:
For your particular case of a diamond, the solution below seems simpler to me than yours. What problems may it create which your solution won't? Or you might refine the problem. It's not easy to see the real value of your suggestions.
``` class HighGobelin: def scream(self): self._speak() print("raAaaaAar") def _speak(self): return
class CorruptedGobelin(HighGobelin): def _speak(self): print("my corrupted soul makes me wanna scream")
class ProudGobelin(HighGobelin): def _speak(self): print("I ... can't ... contain my scream!")
class HalfBreed(ProudGobelin, CorruptedGobelin): @property def _speak(self): return super( __class__ if random.choices([True, False]) else ProudGobelin, self )._speak ```
Best regards, Takuo Matsuoka
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. Another one is that even if you're not in the case of a lib, you're likely not to think of this solution (depending on your skills / experiences with python), and not to identify the problem on its own, and debugging it will be a nightmare, unless you already know about super tendency to jump sideway. The problem is not that we can't come up with solutions now. Thanks for your constructive participation :)