Organisation of python classes and their methods

Chris Angelico rosuav at gmail.com
Fri Nov 2 05:15:11 EDT 2012


On Fri, Nov 2, 2012 at 7:08 PM, Martin Hewitson <martinhewitson at mac.com> wrote:
>
> On 2, Nov, 2012, at 08:38 AM, Paul Rubin <no.email at nospam.invalid> wrote:
>
>> Martin Hewitson <martinhewitson at mac.com> writes:
>>> So, is there a way to put these methods in their own files and have
>>> them 'included' in the class somehow? ... Is there an official python
>>> way to do this? I don't like having source files with 100's of lines
>>> of code in, let alone 1000's.
>>
>> That code sounds kind of smelly... why are there so many methods per
>> class?
>
> Simply because there are many different ways to process the data. The class encapsulates the data, and the user can process the data in many ways. Of course, one could have classes which encapsulate the algorithms, as well as the data, but it also seems natural to me to have algorithms as methods which are part of the data class, so the user operates on the data using methods of that class.

Are these really needing to be methods, or ought they to be
module-level functions? Remember, Python code doesn't have to be
organized into classes the way Java code is.

ChrisA



More information about the Python-list mailing list