0

I want to do two classes: The first one Person and the second one Messages

class Person():
    def __init__(self, name):
        self.name = name

class Messages():
     def say_hello(person)
         pass //Say hello from 'name'

And I want to create an object where I can send the message and the sender.

So I have two options:

Make class Person(Messages) a child from Messages. And I could send messages like:

p1 = Person('Ryan')
p1.say_hello(p1)

Or make class Messages(Person) a child from Person. And I could send messages like:

messages = Message()
messages.say_hello(Person('Ryan')) //Here is my problem

I don't know if I can even do this and I don't know what is the best solution or the best way to achieve it. And I need to have two different classes, I could do it in one class but there's a ton of messages to declare that it would be illegible.

Geo30
  • 99
  • 1
  • 6
  • Are you looking for [mixins](https://stackoverflow.com/questions/533631/what-is-a-mixin-and-why-are-they-useful)? – nonDucor Mar 04 '22 at 14:08
  • We're not going to decide for you. You should try the first option and report back when you first encounter a problem. – quamrana Mar 04 '22 at 14:14
  • It's not obvious that either should inherit from the other. Is `Messages.say_hello` supposed to use the person's name in some way? What does a `Messages` method do differently than an ordinary function `def say_hello(person)` would do? – chepner Mar 04 '22 at 14:19

0 Answers0