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:
- initialization/destruction
- input/output
- calculations
- 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.


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to