Please allow me to illustrate my question with a simple example. Let's suppose we have a Customer class:
class Customer:
def __init__(self, name, surname, email):
self.name = name
self.surname = surname
self.email = email
And we also have a Bill class that needs info from a Customer object instance. Should I write the Bill by providing a Customer object instance as an argument?
class Bill:
def __init__(self, amount, customer):
self.amount = amount
self.customer = customer
def to_txt(self):
with open("bill.txt", "w") as file:
file.write(f"{self.customer.name} due amount is {self.amount}")
customer = Customer("John", "Smith", "john@gmail.com")
bill = Bill(100, customer)
Or should Bill simply get a name as an argument as shown below?
class Bill:
def __init__(self, amount, period, customer):
self.amount = amount
self.period = period
self.customer_name = customer_name
def to_txt(self):
with open("bill.txt", "w") as file:
file.write(f"{self.customer_name} due amount is {self.amount}")
customer = Customer("John", "Smith", "john@gmail.com")
bill = Bill(100, customer.name)
Edit: A user dubbed this question as a duplicate, but that question is about passing attributes between different methods in the same class. My question is about passing attributes between different classes.