DEV Community

James Hubert
James Hubert

Posted on

1 1

Intro to Python: Day 14 - OOP - Method signatures in polymorphism

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.

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

Top comments (0)

👋 Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay