How should I properly satisfy the Liskov Substitution Principle in this sample?
class User(ABC): # App core logic
def add_photo(self, photo: bytes, ) -> None:
...
class FacebookUser(User): # API interation logic
def add_photo(self, photo: custom_type, ) -> None:
... # Set of Facebook specific actions.
super().add_photo(photo=photo.bytes, )
I know 4 solutions:
- Name mangling. Flaws:
Forcing me to rename all the existing code withParent.add_photo
and probably all the rest methods. - Composition. Flaws:
2.1. Can't reflect the logical relation between the classes.
2.2 Forcing me to implement (proxy) methods for everyParent
method. if
checking for theself
object type inside the method. Flaws:
3.1. Additional complexity and clumsy branches.- Implement
convert_photo
method fromcustom_type
tobytes
type inside theFacebookUser
child class. Flaws:
4.1 I still need to place a newconvert_photo
method inside some kinda "event" method (set of methods) and the best name for it isadd_photo
.
Aucun commentaire:
Enregistrer un commentaire