Hi there 👋 I'm a New York City based web developer documenting my journey with React, React Native, and Python for all to see. Please follow my dev.to profile or my twitter for updates and feel free to reach out if you have questions. Thanks for your support!
We're following up on yesterday's article on polymorphism with a brief discussion of function and method signatures and best practices in Python inheritance.
As discussed, polymorphism is the ability for multiple different classes, with different methods and data, to inherit from the same parent class. This makes it easier to create new classes that share methods that are on the parent.
In computer programming, a function signature is a term for the inputs and outputs of a function. To use the boot.dev definition in OOP Chapter 5 on Polymorphism:
A function signature includes the name, inputs, and outputs of a function or method.
In functional programming, each function is recognized to have its own distinct function signature, and there is no inheritance as such. In OOP, inheritance is one of the major benefits.
This means we need to take care though not to confuse users of our code, especially when overriding methods on child classes. So, it is a best practice NOT to change the method signature of a class method which inherits from a parent, even when overriding the method.
If you like projects like this and want to stay up to date with more, check out my Twitter @stonestwebdev, I follow back! See you tomorrow for another project.
Top comments (0)