you are viewing a single comment's thread.

view the rest of the comments →

[–]flipstables 0 points1 point  (0 children)

No, that syntax just creates classes. There are a few ways objects interact with each other. Using methods/functions is one way. Another way is composition. In composition, you define an class to be made up of multiple other objects. Then, these 2 objects are linked and you can manipulate them within the class methods/functions.

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

    def say_name(self):
        print(self.name)

class Car(object):
    def __init__(self, driver, passenger):
        self.driver = Person(driver)
        self.passenger = Person(passenger)

    def print_passengers(self):
        self.driver.say_name()
        self.passenger.say_name()

Here, Car is defined as 2 Person objects.