On Fri, Mar 24, 2017 at 9:05 AM, Rafael Knuth <rafael.kn...@gmail.com> wrote: > I have another question :) > I noticed that you split your class into three methods: > > def __init__(self): > # initialize instances of class > > def make_shopping_list(self): > # input > > def display_shopping_list(self): > # output > > I was wondering what common practices are to structure a class? > Thanks :)
Like Alan is his response, I am not totally certain what you are actually asking. If the question is, "Why didn't I write a single method for all of the above instead of three methods?", then it is because each method/function should have (if possible) a single, well-defined purpose to accomplish. And I think you have gotten that by how you replaced my actual code with "#initialize instances of class", "#input" and "#output". This makes things easier for people to understand my code, breaks apart unnecessary interdependencies that would otherwise exist in "big" methods/functions, makes it easier for me to write tests for each function without having to worry about unnecessary dependencies that I will have simulate or mock, etc. -- boB _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor