Sharing a method (function) among several objects.

Discussion in 'Python' started by xifxif@gmail.com, Feb 27, 2005.

  1. Guest

    Hello

    There are several different objects. However, they all share the same
    function.

    Since they are not the same or similar, it's not logical to use a
    common superclass.

    So I'm asking, what's a good way to allow those objects to share that
    function?

    The best solution I've found so far is to put that function in a
    module, and have all objects import and use it. But I doubt that's a
    good use-case for modules; writing and importing a module that contains
    just a single function seems like an abuse.

    Thanks,
    Xif
     
    , Feb 27, 2005
    #1
    1. Advertising

  2. > Since they are not the same or similar, it's not logical to use a
    > common superclass.


    As python supports multiple inheritance, it's very well "logical" to do it
    by subclassing.

    >
    > So I'm asking, what's a good way to allow those objects to share that
    > function?
    >
    > The best solution I've found so far is to put that function in a
    > module, and have all objects import and use it. But I doubt that's a
    > good use-case for modules; writing and importing a module that contains
    > just a single function seems like an abuse.


    A module is a unit of code that (should) encapsulate a certain
    functionality. So it's perfect for your needs. There is no law or even rule
    of thumb that makes claims about module size (or the lack of, for this
    matter). So create a module - it doesn't cost you anything.
    --
    Regards,

    Diez B. Roggisch
     
    Diez B. Roggisch, Feb 27, 2005
    #2
    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. Xin Li
    Replies:
    2
    Views:
    417
    Steve C. Orr [MVP, MCSD]
    Jun 27, 2004
  2. qube3
    Replies:
    4
    Views:
    985
    qube3
    Jun 24, 2005
  3. Richard
    Replies:
    11
    Views:
    792
    Jesper Nordenberg
    May 4, 2004
  4. Fuming Wang
    Replies:
    7
    Views:
    342
    =?iso-8859-1?q?Fran=E7ois_Pinard?=
    Jul 17, 2003
  5. Ted Byers
    Replies:
    1
    Views:
    82
Loading...

Share This Page