[Tutor] Using Class Properly - early beginner question
alan.gauld at yahoo.co.uk
Fri Mar 24 21:40:07 EDT 2017
On 24/03/17 21:42, boB Stepp wrote:
>> I noticed that you split your class into three methods:
Many real world classes have a lot more than 3 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?
I'm not sure exactly what you mean and there are no rules
but some programmers group related methods (as Bob did
albeit with only one method per "group")
Some possible categories:
- event handlers (eg in a GUI)
- operations (eg __add__, __sub__, __str__ etc)
- (internal) helpers.
But others prefer to order their methods alphabetically.
Or to sort them alphabetically within the groups.
There are no hard and fast rules.
Author of the Learn to Program web site
Follow my photo-blog on Flickr at:
More information about the Tutor