Re: Organisation of python classes and their methods

Discussion in 'Python' started by Ulrich Eckhardt, Nov 2, 2012.

  1. Am 02.11.2012 09:20, schrieb Martin Hewitson:
    > Well, here we disagree. Suppose I have a class which encapsulates
    > time-series data. Below is a list of the absolute minimum methods one
    > would have to process that data.

    [...]
    > 'abs' 'acos' 'asin' 'atan' 'atan2' 'average' 'cohere' 'conv' 'corr'
    > 'cos' 'cov' 'cpsd' 'detrend' 'dft' 'diff' 'downsample' 'exp'
    > 'export' 'fft' 'fftfilt' 'filter' 'filtfilt' 'find' 'heterodyne'
    > 'hist' 'imag' 'integrate' 'interp' 'join' 'le' 'lincom' 'ln' 'load'
    > 'log' 'log10' 'lscov' 'max' 'mean' 'median' 'min' 'minus' 'mode'
    > 'mpower' 'mrdivide' 'mtimes' 'ne' 'norm' 'or' 'plot' 'plus'
    > 'polyfit' 'power' 'psd' 'rdivide' 'real' 'resample' 'rms' 'round'
    > 'save' 'scale' 'search' 'select' 'sin' 'smoother' 'sort'
    > 'spectrogram' 'split' 'sqrt' 'std' 'sum' 'sumjoin' 'svd' 'tan' 'tfe'
    > 'timeaverage' 'times' 'timeshift' 'transpose' 'uminus' 'upsample'
    > 'zeropad'



    Just as a suggestion, you can separate these into categories:

    1. Things that modify the data, yielding a different (although derived)
    data set, e.g. import/load, split, join, plus, minus, zeropad.
    2. Things that operate on the data without modifying it, e.g.
    export/save, average, find, plot, integrate.

    The latter can easily be removed from the class. Since they don't touch
    the content, they can't invalidate internals and can't break encapsulation.

    For the former, providing general means to construct or modify the data
    (like e.g. adding records or joining sequences) is also all that needs
    to remain inside the class to ensure internal consistency, everything
    else can be built on top of these using external functions.


    Uli
    Ulrich Eckhardt, Nov 2, 2012
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Paul Rubin
    Replies:
    10
    Views:
    265
    Steven D'Aprano
    Nov 3, 2012
  2. Peter Otten
    Replies:
    0
    Views:
    180
    Peter Otten
    Nov 2, 2012
  3. Robert Kern
    Replies:
    0
    Views:
    215
    Robert Kern
    Nov 2, 2012
  4. Peter Otten
    Replies:
    0
    Views:
    227
    Peter Otten
    Nov 2, 2012
  5. Frank Millman
    Replies:
    0
    Views:
    247
    Frank Millman
    Nov 2, 2012
Loading...

Share This Page