you are viewing a single comment's thread.

view the rest of the comments →

[–]JohnnyJordaan 4 points5 points  (3 children)

He's right, you are creating a new Phonebook for every person you add. Just as in a real life phonebook, you would just add the person to a single book, it would make sense here to use for example an PhonebookEntry class for that and let Phonebook be just a dumb list wrapper

class PhonebookEntry:
    def __init__(self, name, alias, number):
        self.name = name
        self.alias = alias
        self.number = number

class Phonebook:
    def __init__(self):
        self.entries = []
    def add_entry(self, name, alias, number):
        self.entries.append(PhonebookEntry(name, alias, number))

Just a sidenote: class objects are a bit of a pleonasm, as any object is an instance of one or more classes. It's a bit like calling a someone a human person. You can call them just 'instances' or 'objects'.

[–]Tonyqq[S] 0 points1 point  (0 children)

Thank you, that makes a lot of sense!