Suppose I have this class:
class Bunch_of_comments(): def __init__(self, *list_of_comments, date=datetime.now()): self.date = date self.list_of_comments = [] self.comments_counter = 0 self.list_of_comments.append(list_of_comments) self.comments_counter += len(list_of_comments) I want to make it a getter on the list_of_comments list. Here is the action
def get_list_of_comments(self): return self.get_list_of_comments() # don't forget to find out about return value breaks encapsulation because the link to the list is returned, which means that the one who accepts it can do with it everything he wants, for example, add elements without a setter to it.
What to do ?
obj.list_of_comments = [1, 2, 3]or evenobj.list_of_comments = "Bla Bla Bla". - pank__nameshould be considered private, but in fact they will still be public and anyone can change them. Nothing - can you do such a language. - pank