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 Q Developer image

Your AI Code Assistant

Generate and update README files, create data-flow diagrams, and keep your project fully documented. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

Top comments (0)

Sentry image

See why 4M developers consider Sentry, β€œnot bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

πŸ‘‹ Kindness is contagious

Please leave a ❀️ or a friendly comment on this post if you found it helpful!

Okay